码迷,mamicode.com
首页 > Web开发 > 详细

MVC6 (ASP.NET5) 认证 (Asp.net identity) cookie模式 自定义认证

时间:2015-12-09 08:47:16      阅读:612      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!