不显示的时候状态code不是200自404页 [英] Custom 404 Page not showing when StatusCode is not 200
本文介绍了不显示的时候状态code不是200自404页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的的web.config
文件我已经启用自定义错误:
In my web.config
file I have custom errors enabled:
<customErrors mode="On" defaultRedirect="~/Error">
<error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
我的 NOTFOUND
动作:
public ActionResult NotFound()
{
Response.StatusCode = 404; //no issues when this is not set
return View();
}
问题:
这种配置能正常工作在本地服务器上,但是当我移动到远程服务器自定义404页面不显示(IIS默认的404显示),除非状态code NOTFOUND
操作设置为200。
有人能解释一下这是怎么回事?
Could someone explain what's going on?
推荐答案
您也想通过设置来禁用IIS自定义错误<一个href=\"https://msdn.microsoft.com/en-us/library/system.web.htt$p$psponse.tryskipiiscustomerrors%28v=vs.110%29.aspx\"相对=nofollow> TrySkipIisCustomErrors 来实现。
You also want to disable IIS custom errors by setting TrySkipIisCustomErrors to true.
public ActionResult NotFound()
{
Response.StatusCode = 404;
Response.TrySkipIisCustomErrors = true; <---
return View();
}
这篇关于不显示的时候状态code不是200自404页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文