Asp.net mvc 5 使用OWIN的MVC5 Cookie身份验证卡在循环中

Asp.net mvc 5 使用OWIN的MVC5 Cookie身份验证卡在循环中,asp.net-mvc-5,owin,Asp.net Mvc 5,Owin,我正在尝试在MVC5中使用基本的cookie身份验证,我使用以下代码成功地调用了signin。然而,登录在一个循环中被调用,我得到一个错误“这个网页有一个重定向循环” 我看不出这里有什么问题,看起来只是没有设置cookie AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = new ClaimsIdentity(new[] {

我正在尝试在MVC5中使用基本的cookie身份验证,我使用以下代码成功地调用了signin。然而,登录在一个循环中被调用,我得到一个错误“这个网页有一个重定向循环”

我看不出这里有什么问题,看起来只是没有设置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);

您是否将401状态设置为响应的任意位置?401可能会被身份验证中间件重定向,这可能导致此循环。据我所知,这是不可能的。我所做的就是调用signin并重定向到returnurl