zoukankan      html  css  js  c++  java
  • MVC6 (ASP.NET5) 认证 (Asp.net identity) cookie模式 自定义认证

    1、Startup类的Configure方法中, 

    app.UseIdentity();

    改为

    app.UseCookieAuthentication(options =>
                { 
                    options.AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    options.AutomaticAuthenticate = true;
                    options.AutomaticChallenge = true; 
                    options.CookieHttpOnly = true; 
                });

    2、登录的Action方法中:

    1             List<Claim> claims = new List<Claim>();
    2             claims.Add(new Claim("Name", "TestName", ClaimValueTypes.String));
    3             claims.Add(new Claim(ClaimTypes.Name, "TestName", ClaimValueTypes.String));
    4             ClaimsIdentity identity = new ClaimsIdentity(claims, "AuthenticationType", "Name", ClaimTypes.Role);
    5             ClaimsPrincipal principal = new ClaimsPrincipal(identity);
    6             HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);
    7             return View();
  • 相关阅读:
    CAP.dll of dotnetcore
    GRPC 高性能 RPC 框架, 服务间通讯
    REST Client
    ERP Export
    ERP Update DataSource
    knockout js
    面试题目总结
    JavaScript Objiects and Prototypes
    PLS-00172: string literal too long
    字符串连接性能
  • 原文地址:https://www.cnblogs.com/ybst/p/5031686.html
Copyright © 2011-2022 走看看