使用标识更改.NET Core 2.2中的登录/注销页面

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

我在.net核心的每个版本中都做了不同的操作但是现在在2.2中我无法正确地重定向我的代码。

这是我在startup.cs中使用的documentation

(这是一个默认的新的干净项目)

services.AddMvc()
    .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
    .AddRazorPagesOptions(options =>
    {
      options.AllowAreas = true;
      options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
      options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
    });

services.ConfigureApplicationCookie(options =>
  {
    options.LoginPath = $"/Identity/Account/Login";
    options.LogoutPath = $"/Identity/Account/Logout";
    options.AccessDeniedPath = $"/Identity/Account/AccessDenied";
  });

更改登录或注销路径当前不执行任何操作。这里有任何关于我可能遗失的建议吗?

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

好的!问题得到确认。如果你使用.AddDefaultUI()身份服务注册,那么覆盖默认的options.LoginPath将无法正常工作。因此,要使用您的自定义登录路径进行未经授权的用户重定向,请注释掉.AddDefaultUI(),如下所示:

services.AddIdentity<ApplicationUser, IdentityRole>()
                //.AddDefaultUI(UIFramework.Bootstrap4) <-- you have to comment out this
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

现在它应该工作。这是Github Issue

© www.soinside.com 2019 - 2024. All rights reserved.