use*_*994 3 c# asp.net asp.net-mvc web-config http-status-codes
我有以下几点:
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>
Run Code Online (Sandbox Code Playgroud)
ErrorController
[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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
FilterConfig
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
//filters.Add(new HandleErrorAttribute());
}
Run Code Online (Sandbox Code Playgroud)
在本地一切正常,我得到一个自定义错误页面并且很高兴,但是一旦我将站点部署到我的 Web 服务器,我就不再收到我的自定义错误消息,只有通用错误消息:
我是否需要在我的在线环境中添加任何特定于 IIS 配置的内容?
我已经将本地Web.config与部署进行了比较,Web.config没有任何不同(我可以看到)。
您的错误被 IIS 自定义错误覆盖。
尝试:
Response.TrySkipIisCustomErrors = true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
842 次 |
| 最近记录: |