2

I am using the solution detailed in this SO Question. I've used this on other sites before and its worked fine, and it works on my dev box. However, when I publish to a our Windows VPS, errors return the standard IIS error page.

I have never administered a web server before, and I am not sure what settings I need to check to figure out why its not returning the custom errors I have set up. I have tried setting .net error pages for the app to off and on, with the default page set to the root site, as well as just '/'.

I have also tried setting the error pages (under iis in 7.5) to custom and detailed.

None of these seem to have any effect on the error page that is returned. What am I doing wrong here?

Community
  • 1
  • 1
Kyeotic
  • 19,697
  • 10
  • 71
  • 128
  • What error page are you seeing? That will give us an idea of what is handeling the error. From there was can figure out what settings to try next. – Nick Bork Jan 04 '12 at 18:40
  • Its the standard iis error page. Here is an example I found on google: http://www.west-wind.com/Weblog/images/200901/WindowsLiveWriter/Response.TrySkipIisCustomErrors_9A81/ServerError500_5436e95f-b1b5-46eb-80ab-0769a875117d.png – Kyeotic Jan 04 '12 at 18:42

2 Answers2

1

I remember having similar problem and I added this line to the code

 protected void Application_Error()
 {
 var exc = Server.GetLastError();
 var httpExc = exc as HttpException;
 Response.Clear();
 Server.ClearError();
 var routeData = new RouteData();
 routeData.Values["controller"] = "Error";
 routeData.Values["action"] = "General";
 routeData.Values["exception"] = exc;
 Response.StatusCode = 500;
 if (httpExc != null)
 {
     Response.StatusCode = httpExc.GetHttpCode();
     routeData.Values["action"] = "Http404";
     routeData.Values["exception"] = httpExc;
 }
 Response.TrySkipIisCustomErrors = true; //this fixed it
 IController errorsController = new WWS_Website.Controllers.ErrorController();
 var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
 errorsController.Execute(rc);

 }
bobek
  • 8,003
  • 8
  • 39
  • 75
  • I also found this relevant for deployment on servers at various hosts: http://stackoverflow.com/q/1706934/964043 – dmarietta Apr 07 '14 at 16:11
0

You can replace the standard IIS error pages by using the httpErrors section in the system.webServer section in your web.config file. This is in addition to the customErrors section in system.web.

<system.webServer>
    ...
    <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
        <remove statusCode="400" subStatusCode="-1" />
        <error statusCode="400" prefixLanguageFilePath="" 
            path="/errors/400" responseMode="ExecuteURL" />
        <remove statusCode="404" subStatusCode="13" />
        <error statusCode="404" subStatusCode="13" prefixLanguageFilePath=""
            path="/errors/file-upload-too-large" responseMode="Redirect" />
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" 
            path="/errors/404" responseMode="ExecuteURL" />
        <remove statusCode="403" subStatusCode="-1" />
        <error statusCode="403" prefixLanguageFilePath="" 
            path="/errors/403" responseMode="ExecuteURL" />
    </httpErrors>
danludwig
  • 46,965
  • 25
  • 159
  • 237