Asp.net MVC在IIS 7下发布的网站显示空白页面

时间:2015-01-09 06:59:26

标签: c# asp.net-mvc iis

昨天我在IIS中使用.Net framework 4.5部署了一个站点,它返回了空白页面而没有告诉我任何关于什么错误的信息。这个网站在我的开发环境中运行良好。我进一步注意到在global.ascx.cs中我处理了以下事件中的所有错误

protected void Application_Error(object sender, EventArgs e)
{
    var exception = Server.GetLastError();

    var logger = LogManager.GetLogger(this.GetType());
    logger.Error("Application_Error", exception);

    var httpContext = ((MvcApplication)sender).Context;
    var currentController = " ";
    var currentAction = " ";
    RouteData currentRouteData = null;
    try
    {
        currentRouteData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext));
    }
    catch { }

    if (currentRouteData != null)
    {
        if (currentRouteData.Values["controller"] != null && !String.IsNullOrEmpty(currentRouteData.Values["controller"].ToString()))
        {
            currentController = currentRouteData.Values["controller"].ToString();
        }

        if (currentRouteData.Values["action"] != null && !String.IsNullOrEmpty(currentRouteData.Values["action"].ToString()))
        {
            currentAction = currentRouteData.Values["action"].ToString();
        }
    }

    var controller = new ErrorController();
    var routeData = new RouteData();
    var action = "Index";

    if (exception is HttpException)
    {
        var httpEx = exception as HttpException;
        if (httpEx.GetHttpCode() == 404)
        {
            action = "NotFound";

        }
        if (httpEx.GetHttpCode() == 404 && httpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
        {
            action = "NotFoundAjax";
        }
        // others if any
    }

    httpContext.ClearError();
    httpContext.Response.Clear();
    httpContext.Response.StatusCode = exception is HttpException ? ((HttpException)exception).GetHttpCode() : 500;
    httpContext.Response.TrySkipIisCustomErrors = true;

    routeData.Values["controller"] = "Error";
    routeData.Values["action"] = action;

    controller.ViewData.Model = new HandleErrorInfo(exception, currentController, currentAction);
    ((IController)controller).Execute(new RequestContext(new HttpContextWrapper(httpContext), routeData));
}

之后我评论了上面的代码并再次部署了网站,它向我展示了缺少的dll错误

  1. System.Net.Http.WebRequest.dll
  2. System.Net.Http.Formatting.dll
  3. System.Web.Http.WebHost.dll
  4. System.Web.Http.dll
  5. 我复制了这些dll并开始工作了。最后,我取消注释了application_error代码以记录错误。

    如果我们不想评论global.ascx.cs application_error事件,是否有更好的方法来了解编译错误?

0 个答案:

没有答案