刹那的菜鸟

博客园 首页 新随笔 联系 管理

1、直接修改项目 1.1 改成 2.0

 

Startup 的修改

  • 去除构造函数中下面的代码
    复制代码
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
    
    builder.AddEnvironmentVariables();
    Configuration = builder.Build();
    复制代码
  • 去除 Configure 方法中下面的代码
    loggerFactory.AddSerilog();
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  • IConfigurationRoot 改为 IConfiguration
    复制代码
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }
    
    public IConfiguration Configuration { get; set; }
    复制代码

2、授权等要修改下

app.UseAuthentication();

//app.UseCookieAuthentication(new CookieAuthenticationOptions
//{
// AuthenticationScheme = "member", 
// AutomaticAuthenticate = true,     // 是否自动启用验证,如果不启用,则即便客服端传输了Cookie信息,服务端也不会主动解析。
// // 除了明确配置了 [Authorize(ActiveAuthenticationSchemes = "上面的方案名")] 属性的地方,才会解析,此功能一般用在需要在同一应用中启用多种验证方案的时候。比如分Area.
// LoginPath = "/weixin/draw"// 授权页面
//});

 

services.AddCookieAuthentication(options =>
{
    options.CookieHttpOnly = true;
    options.CookieName = "xxx";
    options.CookieDomain = "xxx";
    options.LoginPath = "/account/signin";
    options.LogoutPath = "/account/signout";
});
复制代码

改为

复制代码
services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
    options.Cookie.HttpOnly = true;
    options.Cookie.Name = "xxx";
    options.Cookie.Domain = "xxx";
    options.LoginPath = "/account/signin";
    options.LogoutPath = "/account/signout";
});

 最后更新下 nutget 包

posted on 2017-08-31 11:18  刹那的菜鸟  阅读(286)  评论(0编辑  收藏  举报