Browse Source

Merge pull request #5038 from abpframework/maliming/id4-errorpage

Add Identity service error page to account module.
pull/5082/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
92bedb38b4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.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

9
modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Identity;
using IdentityServer4.Configuration;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Identity.AspNetCore;
using Volo.Abp.IdentityServer;
@ -33,6 +34,12 @@ namespace Volo.Abp.Account.Web
options.FileSets.AddEmbedded<AbpAccountWebIdentityServerModule>();
});
Configure<IdentityServerOptions>(options =>
{
options.UserInteraction.ConsentUrl = "/Consent";
options.UserInteraction.ErrorUrl = "/Account/Error";
});
//TODO: Try to reuse from AbpIdentityAspNetCoreModule
context.Services
.AddAuthentication(o =>

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

@ -0,0 +1,24 @@
@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

@ -0,0 +1,40 @@
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