gpt4 book ai didi

c# - 自定义错误在本地工作,而不是在 IIS 上部署后

转载 作者:行者123 更新时间:2023-11-30 20:42:07 25 4
gpt4 key购买 nike

我有以下内容:

Web.config

<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<customErrors mode="On" defaultRedirect="~/Error/ShowError">
<error redirect="~/Error/ShowError/400" statusCode="400" />
<error redirect="~/Error/ShowError/401" statusCode="401" />
<error redirect="~/Error/ShowError/403" statusCode="403" />
<error redirect="~/Error/ShowError/404" statusCode="404" />
</customErrors>
</system.web>

错误 Controller

[AllowAnonymous]
public class ErrorController : Controller
{
public ViewResult ShowError(int id)
{
Response.StatusCode = id;
switch (id)
{
case 400:
return View("~/Views/Error/400.cshtml");
case 401:
return View("~/Views/Error/401.cshtml");
case 403:
return View("~/Views/Error/403.cshtml");
case 404:
return View("~/Views/Error/404.cshtml");
default:
return View("~/Views/Error/404.cshtml");
}
}
}

过滤配置

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
//filters.Add(new HandleErrorAttribute());
}

在本地一切正常,我得到一个自定义错误页面并且很高兴,但是一旦我将站点部署到我的网络服务器,我就不再收到自定义错误消息,只有通用错误消息:

enter image description here

我是否需要在我的在线环境中添加任何特定于 IIS 配置的内容?

我已经将本地 Web.config 与部署的 Web.config 进行了比较,没有任何不同(我可以看到)。

最佳答案

您的错误已被 IIS 自定义错误覆盖。

尝试:

Response.TrySkipIisCustomErrors = true

关于c# - 自定义错误在本地工作,而不是在 IIS 上部署后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31632928/

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