Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未注册IIS 8异常筛选器_C#_Asp.net_.net_Asp.net Mvc 4_Iis - Fatal编程技术网

C# 未注册IIS 8异常筛选器

C# 未注册IIS 8异常筛选器,c#,asp.net,.net,asp.net-mvc-4,iis,C#,Asp.net,.net,Asp.net Mvc 4,Iis,我有一个带有错误过滤器的MVC4应用程序来捕获所有未处理的异常 public class GlobalErrorHandler : FilterAttribute, IExceptionFilter { private readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(GlobalErrorHandler)); public void OnException(Except

我有一个带有错误过滤器的MVC4应用程序来捕获所有未处理的异常

public class GlobalErrorHandler : FilterAttribute, IExceptionFilter
    {
        private readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(GlobalErrorHandler));

        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
                return;

            var statusCode = (int)HttpStatusCode.InternalServerError;
            if (filterContext.Exception is HttpException)
            {
                statusCode = (filterContext.Exception as HttpException).GetHttpCode();
            }
            else if (filterContext.Exception is UnauthorizedAccessException)
            {
                //to prevent login prompt in IIS
                // which will appear when returning 401.
                statusCode = (int)HttpStatusCode.Forbidden;
            }

            var controllerName = (string)filterContext.RouteData.Values["controller"];
            var actionName = (string)filterContext.RouteData.Values["action"];
            var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
            var result = new ViewResult
                                    {
                                        ViewName = "~/Views/Shared/Error.cshtml",
                                        ViewData = new ViewDataDictionary<HandleErrorInfo>(model),
                                    };
            filterContext.Result = result;


            logger.Error("Error Controller: " + controllerName + " Action: "+ actionName + "Exception: " + filterContext.Exception.StackTrace);
            // Prepare the response code.
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.StatusCode = statusCode;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
        }
    }
在VisualStudion和IIS 7.5(Win 7)上,它按预期工作(显示自定义错误页面),但在IIS 8.5(Win Server 2012 R2)上,当引发一些未处理的异常时,会显示内部服务器错误页面。如何在IIS 8上启用错误处理程序

编辑:可能的副本。我明天试试。

添加

<system.webServer>
    <httpErrors errorMode="Detailed" />
</system.webServer>

正如这里所说的,解决了这个问题

<system.webServer>
    <httpErrors errorMode="Detailed" />
</system.webServer>