【问题标题】:Http 500 error causes blank page in deployed MVC applicationHttp 500 错误导致部署的 MVC 应用程序中出现空白页
【发布时间】:2014-05-30 12:40:54
【问题描述】:

我在这里遇到了一些问题。我有一个已部署到 Windows Server 2008 上的 IIS 7 的 MVC 应用程序。在 Visual Studio 2012 中,每当发生内部服务器错误时,即 http 500,它都会显示我为它设计的页面。但是,当我将它部署到 IIS 时,它会显示一个空白页面,这可能很烦人,因为根本看不到应用程序的页面。我所需要的只是显示错误页面,而不是当前显示为客户端站点中已部署应用程序的空白页面。然后我可以修复 Visual Studio 中的错误。如果我违反了 S.O. 的任何规则,请原谅我

这是我在 ErrorController.cs 中设置的内容

public ActionResult ForbiddenPage()
{ 
    Response.StatusCode = 403;
    Response.TrySkipIisCustomErrors = true; // add this line
    return View();
}
//
// GET: /Error/

public ActionResult PageNotFound()
{ 
    Response.StatusCode = 404;
    Response.TrySkipIisCustomErrors = true; // add this line
    return View();
}

//
// GET: /Error/

public ActionResult InternalServerError()
{ 
    Response.StatusCode = 500;
    Response.TrySkipIisCustomErrors = true; // add this line
    return View();
}

在 web.config 中,这就是我所拥有的:

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." ...
</handlers>
<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="403" />
  <error statusCode="403" responseMode="ExecuteURL" path="/Error/ForbiddenPage" />
  <remove statusCode="404" />
  <error statusCode="404" responseMode="ExecuteURL" path="/Error/PageNotFound" />
  <remove statusCode="500" />
  <error statusCode="500" responseMode="ExecuteURL" path="/Error/InternalServerError"/>
</httpErrors>
</system.webServer>

我的 RouteConfig.cs 看起来像这样

routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
 defaults: new { controller = "Home", action = "LogIn",id = UrlParameter.Optional } 

    );

    routes.MapRoute(
        "403-ForbiddenPage",
        "{*url}",
        new { controller = "Error", action = "ForbiddenPage" }
    );
    routes.MapRoute(
        "404-PageNotFound",
        "{*url}",
        new { controller = "Error", action = "PageNotFound" }
    );
    routes.MapRoute(
        "500-InternalServerError",
        "{*url}",
        new { controller = "Error", action = "InternalServerError" }
    );

应该显示的视图如下:

@{
    ViewBag.Title = "Internal Server Error"; 
    Layout = "~/Views/Shared/_LayoutError.cshtml"; 
}

<h2></h2>

<div class="list-header clearfix">
    <span>Internal Server Error</span>
</div>
<div class="list-sfs-holder">
  <div class="alert alert-error">
    An unexpected error has occurred.... click<a href ="/Home/LogIn"><i><u>here</u></i>

</a> to login again..
  </div> 
</div>    

如果我应该包含任何内容来帮助您提供解决方案,请在 cmets 中告诉我。

【问题讨论】:

标签: asp.net http


【解决方案1】:

是的,我找到了解决方案, 谢谢ppittle,您对Kev答案的链接有所帮助。我在答案中尝试了这个建议,但它在我的场景中不起作用。但是,Kev 在答案中发布的链接很有帮助。有效的是您的生产服务器 [IIS 所在] 中的 applicationHost.config 中的设置。

在此位置查找名为 applicationHost.config 的文件: C:\Windows\System32\inetsrv\config

将下面的“overrideModeDefault”设置从拒绝更改为允许。

这对我有用。感谢 StackOverflow!

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,但在任何地方都没有看到这个答案:

    运行我的应用程序的用户无权访问在 web.config 中配置的数据库。没有迹象表明这是我能找到的问题。

    我发现这种情况的方法是在 DEBUG 而不是 Release 中进行部署,然后它向我显示了错误消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 2021-08-16
      相关资源
      最近更新 更多