asp.net-core - 使用身份更改 .NET Core 2.2 中的登录/注销页面
问题描述
我在 .net 核心的每个版本中都以不同的方式执行此操作,但是现在在 2.2 中,我无法让我的代码正确重定向。
根据文档,这是我在startup.cs中使用的内容:
(这是一个默认的新建和干净的项目)
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";
});
更改登录或注销路径目前没有任何作用。这里有什么关于我可能遗漏的建议吗?
解决方案
好的!问题已确定。如果您使用.AddDefaultUI()
身份服务注册,则覆盖默认值options.LoginPath
将不起作用。因此,要将您的自定义登录路径用于未经授权的用户重定向,请注释掉.AddDefaultUI()
以下内容:
services.AddIdentity<ApplicationUser, IdentityRole>()
//.AddDefaultUI(UIFramework.Bootstrap4) <-- you have to comment out this
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
现在它应该可以工作了。这是Github 问题
推荐阅读
- r - 如何修复从源代码在 Mac OS X 上安装 RCurl 时出错:找不到“curl/curl.h”文件
- java - 在 Apache Flink SQL 中选择双列时解析错误
- android - 在 200 网络响应上调用 onError 而不是 onNext - RxJava,Retrofit
- android - 我想要一个使用 Deep Link 导航到特定 Flutter 页面的示例
- sql - 找到最后一个参与项目的人(分组/有 sql?)
- loops - SASS @for - 通过与到
- pandas - 如何从包含空值和多个值的一列中创建单独的列?
- c++ - 如何通过“EditorToolbarButton”插件打开 EditorWidget
- javascript - 使用 VanillaJS 从执行的字符串创建脚本元素
- jquery - IONIC Angular8 应用程序生产构建生成错误