Browse Source

Find the error page in AbpErrorPageOptions

pull/5085/head
liangshiwei 6 years ago
parent
commit
81919d7df5
  1. 17
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/Controllers/ErrorController.cs

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

@ -1,10 +1,13 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using AutoMapper.Internal;
using IdentityServer4.Models; using IdentityServer4.Models;
using IdentityServer4.Services; using IdentityServer4.Services;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc; 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.AspNetCore.Mvc.UI.Theme.Shared.Views.Error;
using Volo.Abp.Http; using Volo.Abp.Http;
@ -15,13 +18,16 @@ namespace Volo.Abp.Account.Web.Controllers
{ {
private readonly IIdentityServerInteractionService _interaction; private readonly IIdentityServerInteractionService _interaction;
private readonly IWebHostEnvironment _environment; private readonly IWebHostEnvironment _environment;
private readonly AbpErrorPageOptions _abpErrorPageOptions;
public ErrorController( public ErrorController(
IIdentityServerInteractionService interaction, IIdentityServerInteractionService interaction,
IWebHostEnvironment environment) IWebHostEnvironment environment,
IOptions<AbpErrorPageOptions> abpErrorPageOptions)
{ {
_interaction = interaction; _interaction = interaction;
_environment = environment; _environment = environment;
_abpErrorPageOptions = abpErrorPageOptions.Value;
} }
public async Task<IActionResult> Index(string errorId) public async Task<IActionResult> Index(string errorId)
@ -37,11 +43,18 @@ namespace Volo.Abp.Account.Web.Controllers
errorMessage.ErrorDescription = null; errorMessage.ErrorDescription = null;
} }
return View("~/Views/Error/Default.cshtml", new AbpErrorViewModel return View(GetErrorPageUrl(500), new AbpErrorViewModel
{ {
ErrorInfo = new RemoteServiceErrorInfo(errorMessage.Error, errorMessage.ErrorDescription), ErrorInfo = new RemoteServiceErrorInfo(errorMessage.Error, errorMessage.ErrorDescription),
HttpStatusCode = 500 HttpStatusCode = 500
}); });
} }
private string GetErrorPageUrl(int statusCode)
{
var page = _abpErrorPageOptions.ErrorViewUrls.GetOrDefault(statusCode.ToString());
return string.IsNullOrWhiteSpace(page) ? "~/Views/Error/Default.cshtml" : page;
}
} }
} }

Loading…
Cancel
Save