ASP.NET Core 2.1身份:如何删除默认UI剃刀页面?
在这个问题中扩展答案:
Change routing in ASP.NET Core Identity 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-mvc – ASP.NET MVC将表单值传递给action方法
- asp.net-core – 使用IdentityServer 4和WS-Federation
- 如果是Razor DisplayFor和TextBoxFor MVC4中的其他逻辑
- webforms – ASP.Net Core 1.0是否支持WebForm项目
- C# HttpClient设置cookies的两种办法
- asp.net-mvc – 我可以(并且应该)强制NHibernate将来的查询
- asp.net-mvc-3 – 是否可能显示从ASP.NET MVC 3中的数据库的
- asp.net-mvc – ASP.NET MVC适合复杂的Web应用程序吗?
- asp.net-mvc – 使用DisplayAttribute和自定义资源提供程序
- asp.net – 如何解决错误:当应用程序未在UserInteractive模
- asp.net – IFrame:此内容无法显示在一个框架中
- asp.net – 我应该在Web应用程序中嵌入CSS / Jav
- asp.net – global.asax中应用程序的物理路径
- asp.net-mvc – ASP.NET MVC 4覆盖发出的html名称
- App_GlobalResources(ASP.NET)中的子文件夹
- asp.net-mvc – 使ASP.NET MVC应用程序Web Farm准
- asp.net-mvc – 单元测试我的控制器方法导致一个
- Asp.net MVC中使用JQuery插件ajaxFileUpload上传
- 如何写一段死锁代码
- asp.net – EF,UoW和Repository – 何时在WebFor