ASP.NET Core 2.1身份:如何删除默认UI剃刀页面?
|
在这个问题中扩展答案:
从新的ASP.NET Core 2.1 MVC项目,使用身份验证:个人用户帐户设置,您如何不使用默认UI?它似乎默认安装了Identity Core. 创建项目后,删除默认UI剃刀页面的方法是什么,仍然使用Identity Core? 我可以删除/ Identity /区域,然后创建自己的AccountController吗? 解决方法使用 the article linked by 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();
然而,在Core 2.1的最终版本中,相同的部分被简化为: services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
解决方案是,如果将AddDefaultIdentity更改回AddIdentity,则可以覆盖默认值. I.E.不包括.AddDefaultUI()(也不包括UI),你可以编写自己的. services.AddIdentity<IdentityUser,IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
// .AddDefaultUI()
.AddDefaultTokenProviders();
然后,我认为删除/ 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...
}
显然,如果需要,将ApplicationUser和IdentityRole替换为您自己的类. 2)删除ASP.NET Core 2.1项目默认使用的Identity文件夹. 3)创建一个新的单独的ASP.NET Core 2.0项目(不是“2.1”),在项目创建窗口中选择单个用户帐户身份验证. 4)将AccountController和ManageController以及相应的ViewModel和Views从2.0项目复制到ASP.NET Core 2.1项目. 做到这一点,我到目前为止还没有遇到任何问题. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – ASP .Net文件上载超出最大请求长度错误
- asp.net – 如何尊重“从无Cookie域中提供静态内容”IIS6中
- asp.net – MVP MVC和MVVM之间的区别
- ASP.NET表单认证在iPad上显示登录页面
- asp.net – 防止XSS(跨站脚本)
- asp.net-mvc – VS2012 ProjectTypeGuids在安装ASP.NET和We
- asp.net-mvc – 以Razor语法为Telerik MVC Grid定义一个Tem
- asp.net-mvc – 修改ActionFilter中的模型
- asp.net-mvc-4 – 如何在mvc4中将Json字符串发送到Controll
- asp.net – 我可以在超链接上显式指定NavigateUrl吗?
- asp.net-mvc-3 – 在使用Unity容器时为此对象异常
- asp.net-mvc – 从单个Web服务器迁移到多个Web服
- asp.net – HttpContext.Cache到期
- asp.net – 在运行时更改SqlDataSource.SelectCo
- 使用Gzip在ASP.NET / IIS7中输出乱码错误页面
- asp.net – SignalR,Owin和异常处理
- asp.net – 它是否有助于使用NGEN?
- asp.net-mvc – 获取在Identity 2中具有指定角色
- asp.net-mvc – 更改ASP.NET MVC 3中的默认Model
- asp.net – ValidateRequest = False但是在行动中
