我正在尝试在MVC 5中使用基本的cookie身份验证,我使用以下代码成功调用了signin。然而,在循环unitl中调用Login,我收到错误“此网页有一个重定向循环”。
我看不到这里的失败,看起来就像没有设置cookie一样?
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = new ClaimsIdentity(new[] {
new Claim(ClaimTypes.Name, "Teeko"),
},
DefaultAuthenticationTypes.ApplicationCookie,
ClaimTypes.Name, ClaimTypes.Role);
// if you want roles, just add as many as you want here (for loop maybe?)
identity.AddClaim(new Claim(ClaimTypes.Role, "guest"));
//var ctx = Request.GetOwinContext();
//var authenticationManager = ctx.Authentication;
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity);