2010-08-31 116 views
0

我已经实现了标准的登录控制,一切正常。ASP.NET登录控制劫持我的404

但是,当我输入一个无效的URL时,它会被重定向到登录页面。

例如

mywebsite.com/xxx正确地给出了404

mywebsite.com/xxx.aspx导致重定向到登录页面

我使用ASP.NET 3.5在Windows Server 2008年

我已经设置了web.config中有以下

<httpErrors existingResponse="Replace"> 
<remove statusCode="403" /> 
<remove statusCode="404" /> 
<remove statusCode="500" /> 
<error statusCode="403" path="/xyz/NoAccess.htm" responseMode="Redirect" /> 
<error statusCode="404" path="/xyz/FileNotFound.htm" responseMode="Redirect" /> 
<error statusCode="500" path="/xyz/FileNotFound.htm" responseMode="Redirect" /> 
</httpErrors> 

认证是通过web表单

<authentication mode="Forms"> 
<forms loginUrl="Login.aspx" defaultUrl="~/External/SomeView.aspx"></forms> 
</authentication> 
<authorization> 
<deny users="?"/> 
</authorization> 

如此看来登录页面被劫持我的404 如何使http://www.mywebsite.com/xxx.aspx返回404,而不是重定向到的登录页面?

+0

要清楚我不认为这是授权问题,即403问题。 我已经在指定的/ xyz目录中有一个单独的web.config。事实上,我可以通过访问mywebsite.com/xyz/FileNotFound.htm而无需登录即可看到FileNotFound.htm。 但是,如果我输入类似于mywebsite.com/SomeNonExistantPage.aspx的内容,浏览器将使用以下URL重定向到登录页面mywebsite.com/Login.aspx?ReturnUrl=%2fSomeNonExistantPage.aspx 如果我然后登录,它只会重定向到404页面。 – BigPoo 2010-08-31 12:31:43

回答

4

我认为你需要让你的404页面访问所有用户 - 你可以添加以下到你的web.config:

<location path="/xyz/FileNotFound.htm"> 
    <system.web> 
     <authorization> 
      <allow users="*"/> 
     </authorization> 
    </system.web> 
</location> 
0

不,登录页面没有劫持404结果 - 但是你要返回403,你已经告诉认证模块重定向到登录页面。

我不知道有足够的了解web.config中的错误配置部分的内部运作,而是尝试切换周围的顺序:

<!-- Notice that the 404 rule is before the 403 rule --> 
    <error statusCode="404" path="/xyz/FileNotFound.htm" responseMode="Redirect" /> 
    <error statusCode="403" path="/xyz/NoAccess.htm" responseMode="Redirect" /> 
    <error statusCode="500" path="/xyz/FileNotFound.htm" responseMode="Redirect" /> 

如果不工作,改变你的访问规则允许访问xxx.aspx,删除

<deny users="?" /> 

因为这需要所有用户在他们可以访问任何内容之前登录。 (?匹配任何匿名的,也就是不登录,用户...)