C# 如何解决重定向循环
我有一个web应用程序,一些使用Chrome作为首选浏览器的用户在退出应用程序并尝试重新登录时会出现以下错误 “此网页具有重定向循环” 我的web应用程序使用表单身份验证,而C# 如何解决重定向循环,c#,asp.net,.net,C#,Asp.net,.net,我有一个web应用程序,一些使用Chrome作为首选浏览器的用户在退出应用程序并尝试重新登录时会出现以下错误 “此网页具有重定向循环” 我的web应用程序使用表单身份验证,而FormAuthenticationModule将用户重定向回我的应用程序的登录页面,因此我无法使用这种方法: <customErrors mode="On" defaultRedirect="~/MyErrorPage.aspx" > <error statusCode="401" redire
FormAuthenticationModule
将用户重定向回我的应用程序的登录页面,因此我无法使用这种方法:
<customErrors mode="On" defaultRedirect="~/MyErrorPage.aspx" >
<error statusCode="401" redirect="~/NoAccess.aspx"/>
</customErrors>
然而,由于我添加了这种方法,用户似乎得到了“重定向循环”错误
在清除cookies之后,一切看起来都很好,但问题再次出现
是否有永久性的修复方法可以添加到我的代码中,或者是否有其他方法可以防止此问题发生?尝试将此添加到您的
web.config
文件中:
<location path="NoAccess.aspx">
<system.web>
<authorization>
<allow users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
您可以阅读更多关于位置的信息。
还有更多关于授权的信息。有一个非常类似的问题,并在IIS中解决了它:在
身份验证
功能中启用匿名身份验证
并禁用所有其他功能。这是有道理的,因为最终这是管理身份验证逻辑的应用程序,而不是IIS或ASP.NET。但显然,此解决方案不支持@Grzegorz建议的对公共页面的优雅访问。我还有一个重定向循环,导致错误消息请求过滤模块被配置为拒绝查询字符串过长的请求。
对于身份验证设置为个人用户帐户
请求的URL是http://localhost:52266/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl....
因此,很明显,每次都会不断重定向到登录页面并附加返回URL
在试图查找有问题的循环时,没有多少断点会起作用,因为没有触发断点
最后,我:
- 查找项目属性。通过选择项目(不是解决方案)并查看“属性”窗口(不要右键单击,然后选择“属性”,否则将找不到它)
- 将
匿名身份验证设置为
已启用
- 将Windows身份验证设置为禁用
启动项目时,默认页面现在应该出现,您添加的断点应该开始工作。这是一篇旧文章,我在自定义身份验证和验证时遇到了这个问题。 通过在web.config中添加这行代码,问题得以解决
<system.web>
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" path="/" timeout="240" cookieless="UseCookies"></forms>
</authentication>
<authorization>
<allow users="*"/>
</authorization>
<compilation debug="true" targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
希望有帮助。我最近也开始使用MVC 5,如果遇到这个问题,我会记住你的解决方案。
<location path="Login.aspx">
<system.web>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="public">
<system.web>
<authorization>
<allow users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
<system.web>
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" path="/" timeout="240" cookieless="UseCookies"></forms>
</authentication>
<authorization>
<allow users="*"/>
</authorization>
<compilation debug="true" targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>