zoukankan      html  css  js  c++  java
  • core1.1 升级到 2.0

    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 包

  • 相关阅读:
    [LeetCode] 1474. Delete N Nodes After M Nodes of a Linked List
    [LeetCode] 1836. Remove Duplicates From an Unsorted Linked List
    [LeetCode] 1642. Furthest Building You Can Reach
    [LeetCode] 872. Leaf-Similar Trees
    [LeetCode] 1720. Decode XORed Array
    445. 两数相加 II
    83.删除链表中的重复元素
    笔试题常见的需要模板
    背包问题
    62.63 不同路径
  • 原文地址:https://www.cnblogs.com/zxs-onestar/p/7457370.html
Copyright © 2011-2022 走看看