标签:
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();
MVC6 (ASP.NET5) 认证 (Asp.net identity) cookie模式 自定义认证
标签:
原文地址:http://www.cnblogs.com/ybst/p/5031686.html