Asp.Net Core 6 Cookie 的身份验证策略

参考文献:

http://www.js-code.com/xindejiqiao/xindejiqiao_274882.html

https://www.cnblogs.com/xiaoxiaotank/p/15811749.html

编写代码过程中不理解的代码可参考上面的文献

首先需要配置你的Program.cs,代码如下:

 //在ASP.NET Core应用程序中配置依赖注入容器,将 HttpContextAccessor 注册为一个服务
        builder.Services.AddHttpContextAccessor();

        //选择使用那种方式来身份验证(Cookie)
        builder.Services.AddAuthentication(option =>
        {
            option.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; //默认身份验证方案Cookie
            option.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            option.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            option.DefaultForbidScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            option.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        }).AddCookie(C

你可能感兴趣的:(asp.net,后端,c#,.netcore)