zoukankan      html  css  js  c++  java
  • ASP.Net Core Cookie 身份验证

    创建Cookie身份验证

    • Starup.cs 代码:
        public void ConfigureServices(IServiceCollection services)
        {
            //...
    
            services.AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookie();
    
            //...
        }
    
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // ...
    
            app.UseAuthentication();
    
            //...
        }
    
    • AccountController.cs 代码:
        /// <summary>
        /// 登录 
        /// </summary>
        [HttpPost]
        public async Task<IActionResult> Login(string account, string password, string returnUrl)
        {
            //...
    
            var claimIdentity = new ClaimsIdentity("cookie");
            claimIdentity.AddClaim(new Claim(ClaimTypes.Name, "1"));
            await HttpContext.SignInAsync(
                new ClaimsPrincipal(claimIdentity),
                new AuthenticationProperties { IsPersistent = true });
            
            //...
        }
    
        /// <summary>
        /// 退出登录
        /// </summary>
        public async Task<IActionResult> Logout()
        {
            await HttpContext.SignOutAsync();
        }
    
  • 相关阅读:
    [IMX6]Android6.0移植和分析
    Android设计原则和设计模式
    Linux内核源码目录
    Android源码博客目录
    Android应用博客目录
    imx6的kernel3.4.15启动流程
    dd命令
    shell
    i.mx6 Android5.1.1 build解析
    git总结
  • 原文地址:https://www.cnblogs.com/cc1027cc/p/11439990.html
Copyright © 2011-2022 走看看