加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET Core 2.1身份:如何删除默认UI剃刀页面?

发布时间:2020-12-16 04:31:43 所属栏目:asp.Net 来源:网络整理
导读:在这个问题中扩展答案: Change routing in ASP.NET Core Identity UI? Javier recommends one of the following options when wanting to customise the URLs: Use the scaffolding element of the Default UI and make all necessary customisations yours
在这个问题中扩展答案:
Change routing in ASP.NET Core Identity UI?

Javier recommends one of the following options when wanting to
customise the URLs:

  • Use the scaffolding element of the Default UI and make all necessary customisations yourself.
  • Use a redirection rule that points the old routes to the new routes.
  • Don’t use the Default UI at all.

从新的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项目.

做到这一点,我到目前为止还没有遇到任何问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读