【发布时间】:2011-11-08 06:46:38
【问题描述】:
我使用 Asp.Net 4 和 C#。
我想知道如何更改 Asp.Net customErrors 的默认行为。
在我的Web.Config 文件中,我使用此设置。
<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
当我分析 Result 页面的 Http Header 时,我可以看到:
- 找不到页面时的 404 状态
- 新创建的 url 的 302 状态
我想以这种方式改变这种行为:
- 当一个未找到的页面的请求已经发出http://localhost:1372/nopagehere
- 结果应仅为http://localhost:1372/nopagehere(无 302 重定向)且仅在 404 上具有状态代码。
知道怎么做吗?感谢您抽出宝贵时间。
【问题讨论】:
标签: c# asp.net html http-status-code-404