![core1.1 升级到 2.0 core1.1 升级到 2.0](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
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";
});
![core1.1 升级到 2.0 core1.1 升级到 2.0](https://image.shishitao.com:8440/aHR0cHM6Ly9jb21tb24uY25ibG9ncy5jb20vaW1hZ2VzL2NvcHljb2RlLmdpZg%3D%3D.gif?w=700&webp=1)
改为
![core1.1 升级到 2.0 core1.1 升级到 2.0](https://image.shishitao.com:8440/aHR0cHM6Ly9jb21tb24uY25ibG9ncy5jb20vaW1hZ2VzL2NvcHljb2RlLmdpZg%3D%3D.gif?w=700&webp=1)
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 包