ASP.NET MVC IIS7.5: error handling stopped working properly after moving a website from W7 to Windows 2008 R2

I use the following code in Global.asax.cs to log unprocessed errors and transfer the user to one of the error pages. Error pages are implemented as standard MVC controllers / views.

protected void Application_Error(Object sender, EventArgs e) { Exception ex = HttpContext.Current.Server.GetLastError(); //Handle errors var httpException = ex as HttpException; Response.Clear(); Server.ClearError(); var routeData = new RouteData(); routeData.Values["controller"] = "Errors"; routeData.Values["action"] = "Index"; routeData.Values["exception"] = ex; Response.StatusCode = 500; if (httpException != null) { Response.StatusCode = httpException.GetHttpCode(); switch (Response.StatusCode) { case 403: routeData.Values["action"] = "Http403"; break; case 404: routeData.Values["action"] = "Http404"; log.Error("Error 404 - User sees page not found page", ex); break; } } log.Fatal("USER SEES ERROR 500 PAGE", ex); IController errorsController = new errorsController(); var rc = new RequestContext(new HttpContextWrapper(Context), routeData); errorsController.Execute(rc); } 

It worked great on a development machine (Windows 7 Pro). However, when I moved the site to Windows Server 2008 R2, the error page stopped. Instead, I see standard IIS error pages. However, errors are recorded properly.

What am I doing wrong? Thanks.

+4
source share
1 answer

Be sure to remove the global registration of HandleErrorAttribute attributes from Global.asax . Or, if you are using ASP.NET MVC 2, remove the [HandleError] attribute from your controllers. Also try setting errorMode to "Details":

 <system.webServer> <httpErrors errorMode="Detailed" /> </system.webServer> 
+1
source

Source: https://habr.com/ru/post/1384427/


All Articles