我使用Asp.Net 4和C#。
我想知道如何更改Asp.Net的默认beahviour。
在我的customErrors文件中,我使用此设置。

    <customErrors mode="On" defaultRedirect="/ErrorPages/Oops.aspx">
        <error statusCode="404" redirect="/ErrorPages/404.aspx" />
    </customErrors>

如您所料,如果找不到页面,则会重定向到Web.Config中指定的自定义页面。
请求页面:
http://localhost:1372/nopagehere

结果页:
http://localhost:1372/ErrorPages/404.aspx?aspxerrorpath=/nopagehere

当我分析结果页的Http头时,我可以看到:
找不到页面时的404状态
新创建的url的302状态
我想这样改变这种行为:
当向“未找到”页发出请求时http://localhost:1372/nopagehere
结果应仅为http://localhost:1372/nopagehere(no 302 redirect),状态代码仅为404。
知道怎么做吗?谢谢你在这方面的时间。

最佳答案

我想您正在查找redirectMode部分的<customErrors>属性。
见:http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx
我想你想把它设置为redirectMode="ResponseRewrite"。这会抛出404并显示404页面的内容,但不会重定向到实际的404页面。

07-24 20:06
查看更多