“访问被拒绝”页面 ASP.NET Core Identity

问题描述 投票:0回答:1

我想设置我的“拒绝访问”页面

我用:

Microsoft.AspNetCore.Identity.UI ver. 8.0.0
Microsoft.AspNetCore.Identity.EntityFrameworkCore ver. 8.0.0

我尝试:

builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddCookie(options =>
    {
        options.LoginPath = "/account/login";
        options.LogoutPath = "/account/logout";
        options.AccessDeniedPath = "/account/AccessDenied";
    });

但是当我尝试打开受保护的页面时

/Identity/Account/AccessDenied?ReturnUrl=

为什么会这样?需要更改为

/account/AccessDenied
吗?

谢谢

asp.net-core asp.net-identity
1个回答
0
投票

有两种方法可以修改默认的身份访问拒绝页面。

builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.ConfigureApplicationCookie(options =>
{
    options.LoginPath = "/account/login";
    options.LogoutPath = "/account/logout";
    options.AccessDeniedPath = "/account/AccessDenied";
});

或者

builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.PostConfigure<CookieAuthenticationOptions>(IdentityConstants.ApplicationScheme, options =>
{
    options.LoginPath = "/account/login";
    options.LogoutPath = "/account/logout";
    options.AccessDeniedPath = "/account/AccessDenied";
});
© www.soinside.com 2019 - 2024. All rights reserved.