繁体   English   中英

Aspnet Core 身份管理总是让我返回登录页面

[英]Aspnet Core Identity management always returning me to the login page

在我的应用程序中,我的帐户管理页面不起作用我正在尝试将 go 更改为以下内容。

https://localhost:5001/Identity/Account/Manage

根据我的脚手架,身份管理页面应该在哪里,我已经更改了代码以确保它指向我的 ApplicaitonUser Class 但是由于某种原因,当我访问该页面时,即使我已经登录,它也会让我回到登录状态与登录页面。

在此处输入图像描述

我已经这样配置了我的启动 class

services.AddIdentity<ApplicationUser, IdentityRole>(config =>
{
    config.SignIn.RequireConfirmedEmail = true;
    config.Tokens.AuthenticatorTokenProvider = TokenOptions.DefaultAuthenticatorProvider;
    config.User.RequireUniqueEmail = true;

})
    .AddRoles<IdentityRole>()
    .AddEntityFrameworkStores<MSFSAddonDBContext>()
    .AddDefaultTokenProviders()
    .AddDefaultUI()
    .AddRoles<IdentityRole>();

services.AddScoped<IUserClaimsPrincipalFactory<ApplicationUser>,
AdditionalUserClaimsPrincipalFactory>();
services.AddSession(opts =>
{
    opts.Cookie.IsEssential = false; // make the session cookie Essential
});

确保禁用 cookie 警告,因为我相信如果尚未设置它可能会导致问题。 我还使用以下代码启用了 MFA。

services.ConfigureApplicationCookie(config =>
{
    config.Cookie.Name = "Identity.Cookie";
    config.LoginPath = "/Identity/Account/Login";
});

services.AddAuthorization(options =>
options.AddPolicy("TwoFactorEnabled",
 x => x.RequireClaim("amr", "mfa")));
services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");

cookie 是在调试选项卡的边缘创建的,所以我不知道为什么我的代码拒绝 go 到我正在尝试遵循此处指南的管理页面。

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/mfa?view=aspnetcore-5.0

完整这里是我的配置设置

app.UseHttpsRedirection();
app.UseStaticFiles();
        
app.UseRouting();

app.UseAuthorization();
app.UseAuthentication();


app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
    name: "areas",
    pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");


    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
    endpoints.MapRazorPages();
});

我的问题是我的 AddDefaultUI 覆盖了路径,因此从未找到该页面。 把这个留给其他人,这是 asp.net 核心 5。

模板生成的应用程序不使用授权。 包含 app.UseAuthorization 以确保在应用添加授权时以正确的顺序添加它。 UseRouting、UseAuthentication、UseAuthorization 和 UseEndpoints 必须按照上述代码中显示的顺序调用。

参考: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?source=recommendations&view=aspnetcore-3.1&tabs=netcore-cli

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM