gpt4 book ai didi

asp.net - 当 StatusCode 不为 200 时,自定义 404 页面不显示

转载 作者:行者123 更新时间:2023-12-02 18:45:10 25 4
gpt4 key购买 nike

在我的 web.config 文件中,我启用了自定义错误:

<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),除非 NotFound 操作的状态代码设置为 200。

有人可以解释一下发生了什么吗?

最佳答案

您还想通过设置 TrySkipIisCustomErrors 来禁用 IIS 自定义错误为真。

public ActionResult NotFound()
{
Response.StatusCode = 404;
Response.TrySkipIisCustomErrors = true; <---
return View();
}

关于asp.net - 当 StatusCode 不为 200 时,自定义 404 页面不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29522714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com