Wel*_*ing 19 asp.net asp.net-identity razor-pages asp.net-core-2.1
扩展此问题的答案: 在ASP.NET Core Identity UI中更改路由?
当想要自定义URL时,Javier建议使用以下选项之一:
- 使用默认UI的scaffolding元素并自行进行所有必要的自定义.
- 使用重定向规则将旧路由指向新路由.
- 根本不要使用默认UI.
从新的ASP.NET Core 2.1 MVC项目,使用身份验证:个人用户帐户设置,您如何不使用默认UI?它似乎默认安装在Identity Core上.
创建项目后,删除默认UI剃刀页面的方法是什么,仍然使用Identity Core?
我可以删除该/Identity/区域,然后创建我自己的区域AccountController吗?
Wel*_*ing 21
使用Panagiotis Kanavos链接的文章,我能够找到解决方案.
从ASP.NET Core 2.1.0-preview1中,有一行.AddDefaultUI(),您不必包含在其中Startup.cs.
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultUI()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
然而,在Core 2.1的最终版本中,相同的部分被简化为:
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
Run Code Online (Sandbox Code Playgroud)
该解决方案,如果更改AddDefaultIdentity回AddIdentity,您可以覆盖默认值.IE不包括.AddDefaultUI()(也不支持UI),你可以编写自己的.
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
// .AddDefaultUI()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
然后,我认为删除/Areas/Identity/文件夹是安全的,但我不是100%
更新:
我清理了我的答案,详细说明了我最终使用的最终解决方案,删除了ASP.NET Core 2.1附带的默认身份UI剃刀页面,并使用了MVC.
1)在Startup.cs,
public void ConfigureServices(IServiceCollection services)
{
// Unrelated stuff commented out...
// BEGIN: Identity Setup (Overrides default identity)
services.AddIdentity<ApplicationUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// END: Identity Setup
services.Configure<IdentityOptions>(options =>
{
// Set your identity Settings here (password length, etc.)
});
// More unrelated stuff commented out...
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// Added after AddMvc()
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = $"/account/login";
options.LogoutPath = $"/account/logout";
options.AccessDeniedPath = $"/account/access-denied";
});
// More unrelated stuff commented out...
}
Run Code Online (Sandbox Code Playgroud)
显然,如果需要,可以替换它们ApplicationUser,并IdentityRole使用您自己的类.
2)删除ASP.NET Core 2.1项目默认的Identity文件夹.
3)创建一个新的单独的ASP.NET Core 2.0项目(不是"2.1"),并Individual User Account在项目创建窗口中选择身份验证.
4)将AccountController和ManageController,以及相应的ViewModels和Views,从2.0项目复制到ASP.NET Core 2.1项目.
做到这一点,我到目前为止还没有遇到任何问题.
| 归档时间: |
|
| 查看次数: |
9652 次 |
| 最近记录: |