1

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.

2
  • 1
    I think there is a different web.config setting for IIS (on your server) vs when you are using Visual Studio. Commented May 30, 2014 at 12:52
  • This looks similar: stackoverflow.com/questions/6101110/… Commented May 30, 2014 at 12:54

2 Answers 2

0

Yes I found the solution, Thanks ppittle, your link to Kev's answer helped. I tried the suggestion in the answer but it didn't work in my scenario. However, the link posted by Kev in the answer helped alot. What worked was the setting in the applicationHost.config in your production server [where IIS is].

Look for a file called applicationHost.config at this location: C:\Windows\System32\inetsrv\config

Change the "overrideModeDefault" setting below from Deny to Allow.

This is what worked for me. Thanks StackOverflow!

Sign up to request clarification or add additional context in comments.

Comments

0

I had this same issue, but didn't see this answer anywhere:

The user my application was running under didn't have permission to access the database that was configured in the web.config. There was no indication that this was the problem that I could find.

The way I found this was by deploying in DEBUG instead of Release, which then showed me the error message.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.