【发布时间】:2014-04-03 08:54:59
【问题描述】:
我在 MVC4 应用程序中实现了自定义错误页面。基本上我在我的 Web.Config 文件中添加了以下内容:
<customErrors mode="On" defaultRedirect="Error">
<error statusCode="404" redirect="~/Error/NotFound"/>
<error statusCode="500" redirect="~/Error/Index"/>
</customErrors>
不幸的是,如果有人使用向路由添加路径的请求,则不会发生重定向。例如,我有一个 Document 方法,它在控制器 Content 上获取一个 ID。以下请求有效:
/Content/Document/1
当有人调用这样的 url 时,我会显示 404:
/BlaBla
/Content/BlaBla
部分用户设法在 ID 后添加/BlaBla:
/Content/Document/1/Blabla
这是我的自定义 404 页面未显示的情况。我该如何处理?
【问题讨论】:
标签: asp.net-mvc-4 http-status-code-404