-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5085 from abpframework/liangshiwei/account-module…
…-errorPage Add Identity service error controller to account module
- Loading branch information
Showing
3 changed files
with
63 additions
and
64 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...ount/src/Volo.Abp.Account.Web.IdentityServer/Areas/Account/Controllers/ErrorController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 0 additions & 24 deletions
24
modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs
This file was deleted.
Oops, something went wrong.