I am having a bit of an issue here. I have an MVC application that has been deployed to IIS 7 on Windows Server 2008. In Visual Studio 2012, whenever an internal server error occurs i.e. http 500, it shows the page I designed for it. However, when I deploy it to IIS, it shows a blank page which could be very annoying because one does not see the application's page at all. All I need is for the error page to display instead of the blank page that it currently displays as a deployed application in the client's site. I can then work on fixing the error in Visual Studio. Kindly pardon me if I broke any rules of S.O.
Here is what I have setup in my 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(); } In web.config, this is what I have:
<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> My RouteConfig.cs Looks like this
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" } ); The View that should be displayed is below:
@{ 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> If there is any thing that I should have included to aid you in proffering a solution, please let me know in the comments.