【问题标题】:MVC custom error pages work in dev but not in productionMVC 自定义错误页面在开发中有效,但在生产中无效
【发布时间】:2013-09-10 10:08:18
【问题描述】:

我在 MVC4 项目中创建了一些自定义错误页面。我使用 Application_Error 和 HandleErrorAttribute 进行路由。

还有,

它在我的开发计算机上运行良好,在 IIS 8.0 下

当我将项目发布到生产服务器时,在 IIS 7.5 下,它显示的是默认错误页面,而不是自定义页面。

我错过了什么?

【问题讨论】:

  • 您的自定义错误模式是什么? (即 web.config 中的
  • 。无论如何,我不会重新编译项目。我只是将它从我的开发 PC 复制到生产。

标签: asp.net asp.net-mvc-4


【解决方案1】:
 <customErrors mode="On" defaultRedirect="~/Error/Error.html" redirectMode="ResponseRewrite">
      <error redirect="~/Error/403.aspx" statusCode="403" />
      <error redirect="~/Error/404.aspx" statusCode="404" />
      <error redirect="~/Error/500.html" statusCode="500" />
    </customErrors>

在根目录“错误”中创建​​页面403.aspx

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>403 Not Found</title>
</head>
<body>
    <%
    Server.ClearError();
Response.Status = "403 - Forbidden: Access is denied.";
Response.StatusCode = 403;
         %>
    <div>
    <h2>403 - Forbidden: Access is denied.</h2>
    </div>
</body>
</html>

【讨论】:

    【解决方案2】:

    从动作方法中删除任何响应代码设置语句。

    喜欢

     Response.StatusCode = 404;
    

    删除它并尝试一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-24
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多