From 249e64c660351df09e9fdea7b7cba2d7e891ecc3 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Mon, 17 Aug 2020 16:00:00 +0800 Subject: [PATCH] Add Identity service error controller to account module --- .../Controllers/ErrorController.cs | 49 +++++++++++++++++++ .../Pages/Account/Error.cshtml | 24 --------- .../Pages/Account/Error.cshtml.cs | 40 --------------- 3 files changed, 49 insertions(+), 64 deletions(-) create mode 100644 modules/account/src/Volo.Abp.Account.Web.IdentityServer/Controllers/ErrorController.cs delete mode 100644 modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml delete mode 100644 modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Controllers/ErrorController.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Controllers/ErrorController.cs new file mode 100644 index 0000000000..faf4539bc4 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Controllers/ErrorController.cs @@ -0,0 +1,49 @@ +using System.Threading.Tasks; +using IdentityServer4.Models; +using IdentityServer4.Services; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Hosting; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Views.Error; +using Volo.Abp.Http; + +namespace Volo.Abp.Account.Web.Controllers +{ + [Area("account")] + public class ErrorController : AbpController + { + private readonly IIdentityServerInteractionService _interaction; + private readonly IWebHostEnvironment _environment; + + public ErrorController( + IIdentityServerInteractionService interaction, + IWebHostEnvironment environment) + { + _interaction = interaction; + _environment = environment; + } + + public async Task Index(string errorId) + { + var errorMessage = await _interaction.GetErrorContextAsync(errorId) ?? new ErrorMessage + { + Error = L["Error"] + }; + + if (!_environment.IsDevelopment()) + { + // Only show in development + errorMessage.ErrorDescription = null; + } + + + // ReSharper disable once Mvc.ViewNotResolved + return View("~/Views/Error/Default.cshtml", new AbpErrorViewModel + { + ErrorInfo = new RemoteServiceErrorInfo(errorMessage.Error, errorMessage.ErrorDescription), + HttpStatusCode = 500 + }); + } + } +} diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml deleted file mode 100644 index 2b43f1527c..0000000000 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml +++ /dev/null @@ -1,24 +0,0 @@ -@page -@using Localization.Resources.AbpUi -@using Microsoft.AspNetCore.Mvc.Localization -@model Volo.Abp.Account.Web.Pages.Account.ErrorModel -@inject IHtmlLocalizer L -@{ - var errorMessage = Model.ErrorMessage.Error; - var errorDetails = Model.ErrorMessage.ErrorDescription; - if (errorDetails.IsNullOrEmpty()) - { - errorDetails = errorMessage; - errorMessage = L["Error"].Value + "!"; - } -} - -

- @errorMessage -

- -
-

- @errorDetails -

-
diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs deleted file mode 100644 index 90622f7dc3..0000000000 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs +++ /dev/null @@ -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; - } - } - } - } -}