我正在尝试获取我们构建的自定义 404 页面来显示,而不是服务器创建的默认 404 页面。它在本地调试应用程序时按预期工作,但在服务器上运行应用程序时却不行。他们的 web.config 文件看起来完全一样。
<customErrors mode="On" defaultRedirect="~/Error/Index">
<error statusCode="404" redirect="~/Error/NotFound" />
</customErrors>
奇怪的是,当任何关于 的内容被修改时 - 将模式设置为“关闭”或“RemoteOnly”,将“~/Error”更改为“错误”,或完全删除该部分 - 结果总是相同的:我明白了本地看起来不错的 404 页面,但不在服务器上。
在本地调试时,此方法按预期执行:
public class ErrorController : BaseController
{
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult NotFound()
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
ErrorSignal.FromCurrentContext().Raise(new HttpException(404, Request.Url.PathAndQuery + " was not found"));
return View();
}
}
因为它在 Global.asax 中找到了这条路线:
routes.MapRoute(
"NotFound",
"{*path}",
new { controller = "Error", action = "NotFound" });
任何和所有的建议表示赞赏。