如何解决重定向循环 [英] How to solve Redirect Loop

查看:304
本文介绍了如何解决重定向循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,以及谁使用Chrome作为自己的preferred选择的浏览器一些用户,获得当他们注销的应用程序下面的错误,并尝试重新登录。

I have a web application, and some users who use Chrome as their preferred browser of choice, get the following error when they have logged out of the application, and try to log back in.

此网页有重定向循环。

我的Web应用程序使用窗体身份验证,而 FormAuthenticationModule 将用户重定向回登录我的应用程序的网页,所以我不能用这个办法:

My web application uses forms authentication, and the FormAuthenticationModule redirects the user back to the Login page of my application, so I cannot use this approach:

<customErrors mode="On" defaultRedirect="~/MyErrorPage.aspx" >

    <error statusCode="401" redirect="~/NoAccess.aspx"/>

</customErrors>

相反,我已经加入以下到的Page_Load 事件我 LoginPage

if (Request.IsAuthenticated && !string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
{
    Response.Redirect("~/NoAccess.aspx");
}

不过,因为我已经添加了这个方法,用户似乎得到了重定向循环的错误。

However, since I have added this approach, the users seem to get the "Redirect Loop" error.

清除饼干后,一切似乎都很好,但问题不会再出现。

After clearing the cookies, all seems well, but the problem does occur again.

对此有一个永久性的修复,我可以添加到我的code,或者是有什么事我可以发生?

Is there a permanent fix for this I can add to my code, or is there anything else I can do to prevent this issue from happening?

推荐答案

尝试添加到您的web.config 文件:

  <location path="NoAccess.aspx">
    <system.web>
      <authorization>
        <allow users="?"/>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

这将关闭任何授权的这一页,应该停止循环。

This will turn off any authorization for this page and should stop Your loop.

您还可以补充一点:

  <location path="Login.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

这将拒绝对那些已经通过身份验证的所有用户访问您的登录页面。 结合这两个应该让你对所有重定向添加自定义错误。

This will deny access to your login page to all users that are already authenticated. Combining those two should allow You to add custom errors for all redirections.

您也可以考虑为未经授权的访问的目录(如公共/ ),并把所有的错误页面(即不​​要求被授权)内。 然后,你可以这样做:

You may also consider creating a directory for unauthorized access (eg. public/) and placing inside all error pages (that do not require being authorized). Then You can do:

  <location path="public">
    <system.web>
      <authorization>
        <allow users="?"/>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

您可以阅读更多关于位置这里。 而更多关于这里授权

You can read more about location here. And more about authorization here.

这篇关于如何解决重定向循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆