Browse Source

Merge pull request #5085 from abpframework/liangshiwei/account-module-errorPage

Add Identity service error controller to account module
pull/5089/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
d900931cd3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 63
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/Areas/Account/Controllers/ErrorController.cs
  2. 24
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml
  3. 40
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs

63
modules/account/src/Volo.Abp.Account.Web.IdentityServer/Areas/Account/Controllers/ErrorController.cs

@ -0,0 +1,63 @@
using System.Net;
using System.Threading.Tasks;
using AutoMapper.Internal;
using IdentityServer4.Models;
using IdentityServer4.Services;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Views.Error;
using Volo.Abp.Http;
namespace Volo.Abp.Account.Web.Areas.Account.Controllers
{
[Area("account")]
public class ErrorController : AbpController
{
private readonly IIdentityServerInteractionService _interaction;
private readonly IWebHostEnvironment _environment;
private readonly AbpErrorPageOptions _abpErrorPageOptions;
public ErrorController(
IIdentityServerInteractionService interaction,
IWebHostEnvironment environment,
IOptions<AbpErrorPageOptions> abpErrorPageOptions)
{
_interaction = interaction;
_environment = environment;
_abpErrorPageOptions = abpErrorPageOptions.Value;
}
public virtual async Task<IActionResult> Index(string errorId)
{
var errorMessage = await _interaction.GetErrorContextAsync(errorId) ?? new ErrorMessage
{
Error = L["Error"]
};
if (!_environment.IsDevelopment())
{
// Only show in development
errorMessage.ErrorDescription = null;
}
const int statusCode = (int)HttpStatusCode.InternalServerError;
return View(GetErrorPageUrl(statusCode), new AbpErrorViewModel
{
ErrorInfo = new RemoteServiceErrorInfo(errorMessage.Error, errorMessage.ErrorDescription),
HttpStatusCode = statusCode
});
}
protected virtual string GetErrorPageUrl(int statusCode)
{
var page = _abpErrorPageOptions.ErrorViewUrls.GetOrDefault(statusCode.ToString());
return string.IsNullOrWhiteSpace(page) ? "~/Views/Error/Default.cshtml" : page;
}
}
}

24
modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml

@ -1,24 +0,0 @@
@page
@using Localization.Resources.AbpUi
@using Microsoft.AspNetCore.Mvc.Localization
@model Volo.Abp.Account.Web.Pages.Account.ErrorModel
@inject IHtmlLocalizer<AbpUiResource> L
@{
var errorMessage = Model.ErrorMessage.Error;
var errorDetails = Model.ErrorMessage.ErrorDescription;
if (errorDetails.IsNullOrEmpty())
{
errorDetails = errorMessage;
errorMessage = L["Error"].Value + "!";
}
}
<h1>
@errorMessage
</h1>
<div>
<p>
@errorDetails
</p>
</div>

40
modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs

@ -1,40 +0,0 @@
using System.Threading.Tasks;
using IdentityServer4.Models;
using IdentityServer4.Services;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
namespace Volo.Abp.Account.Web.Pages.Account
{
public class ErrorModel : AbpPageModel
{
public ErrorMessage ErrorMessage { get; set; }
private readonly IIdentityServerInteractionService _interaction;
private readonly IWebHostEnvironment _environment;
public ErrorModel(IIdentityServerInteractionService interaction, IWebHostEnvironment environment)
{
_interaction = interaction;
_environment = environment;
}
public async Task OnGet(string errorId)
{
ErrorMessage = await _interaction.GetErrorContextAsync(errorId) ?? new ErrorMessage
{
Error = L["Error"]
};
if (ErrorMessage != null)
{
if (!_environment.IsDevelopment())
{
// Only show in development
ErrorMessage.ErrorDescription = null;
}
}
}
}
}
Loading…
Cancel
Save