【问题标题】:Difference in AspNetCore identity 2.0 and 2.1AspNetCore 身份 2.0 和 2.1 的区别
【发布时间】:2019-03-05 15:08:54
【问题描述】:
  • AddIdentity 和 AddDefaultIdentity 有什么区别

从 AspNetCore 身份 2.0 启动时的配置服务方法

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

        // Add application services.
        services.AddTransient<IEmailSender, EmailSender>();

        services.AddMvc();
    }

从 AspNetCore 身份 2.1 启动中的配置服务方法

 public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection")));
        services.AddDefaultIdentity<IdentityUser>()
            .AddEntityFrameworkStores<ApplicationDbContext>();

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

【问题讨论】:

标签: c# asp.net-core asp.net-core-2.1 asp.net-2.0 asp.net-core-identity


【解决方案1】:

AddDefaultIdentity 是在 ASP.NET Core 2.1 中引入的。调用 AddDefaultIdentity 类似于调用以下内容:

  1. 添加身份

  2. AddDefaultUI

  3. AddDefaultTokenProviders

参考https://github.com/aspnet/Docs/issues/8434

【讨论】:

    猜你喜欢
    • 2020-05-06
    • 2019-02-20
    • 2018-08-14
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    相关资源
    最近更新 更多