这个网页有一个重定向循环asp.net mvc4

时间:2014-04-06 03:57:20

标签: asp.net-mvc-4 authentication cookies routes

我有一个包含以下代码的启动类

 public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType="ApplicationCookie",
                LoginPath = new Microsoft.Owin.PathString("/auth/login")
            });
        }
    }

当我运行我的项目时,

  

网页   / AUTH /登录资讯?RETURNURL =%2Fauth%2Flogin%3FReturnUrl%3D%252Fauth%252Flogin%253FReturnUrl%253D%25252Fauth%25252Flogin%25253FReturnUrl%25253D%2525252Fauth%2525252Flogin%2525253FReturnUrl%2525253D%252525252Fauth%252525252Flogin%252525253FReturnUrl%252525253D%25252525252Fauth% 25252525252Flogin%25252525253FReturnUrl%25252525253D%2525252525252Fauth%2525252525252Flogin%2525252525253FReturnUrl%2525252525253D%252525252525252Fauth%252525252525252Flogin%252525252525253FReturnUrl%252525252525253D%25252525252525252Fauth%25252525252525252Flogin%25252525252525253FReturnUrl%25252525252525253D%2525252525252525252Fauth%2525252525252525252Flogin%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252Fauth%252525252525252525252Flogin%252525252525252525253FReturnUrl%252525252525252525253D%25252525252525252525252Fauth%25252525252525252525252Flogin% 25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252Fauth%2525252525252525252525252Flogin%2525252525252525252525253F RETURNURL%2525252525252525252525253D%252525252525252525252525252Fauth%252525252525252525252525252Flogin%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252Fauth%25252525252525252525252525252Flogin%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252Fauth%2525252525252525252525252525252Flogin%2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252Fauth%252525252525252525252525252525252Flogin%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252Fauth%25252525252525252525252525252525252Flogin%25252525252525252525252525252525253FReturnUrl%25252525252525252525252525252525253D%2525252525252525252525252525252525252Fauth%2525252525252525252525252525252525252Flogin%2525252525252525252525252525252525253FReturnUrl% 2525252525252525252525252525252525253D%252525252525252525252525252525252525252 Fauth%252525252525252525252525252525252525252Flogin%252525252525252525252525252525252525253FReturnUrl%252525252525252525252525252525252525253D%25252525252525252525252525252525252525252F   导致了太多的重定向。为此清除您的cookie   网站或允许第三方cookie可以解决问题。如果没有,它   可能是服务器配置问题,而不是您的问题   计算机。

我清除了我的cookie,但仍未改变。

1 个答案:

答案 0 :(得分:1)

我同意@StephenMuecke这是来自一个 无休止的重定向循环。

如果您尝试登陆的页面需要身份验证才能查看,方法是[Authorize] 在控制器类或:

[Authorize]
public class AccountController:Controller
{

或在控制器ActionResult:

[Authorize]
public ActionResult Index

这会将用户重定向到登录页面。

如果这不允许匿名验证,则用户无法登陆页面 没有登录。

[Authorize]
public ActionResult Login(string message, string returnUrl)
{

因此,应用程序会持续将用户重定向到登录页面,直到有 某种类型的溢出。

你需要使用它:

[AllowAnonymous]
public ActionResult Login(string message, string returnUrl)
{
  

RETURNURL =%2Fauth%2Flogin%3FReturnUrl%3D%252Fauth%252Flogin%253FReturnUrl%253D%25252Fauth%

返回网址需要身份验证,因此登录需要身份验证等等。

同样的原则适用于整个项目。