Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

httperrors in web.config

I am trying to use simple html page when 503 service unavilable error comes.

I am using below in web.config's system.webservers

<httpErrors errorMode="Custom">
  <remove statuscode="503" substatuscode="-1">
  <error statuscode="503" responseMode="File" path="Views/Shared/IISError.htm">
</httpErrors>

This is nt working. I am still getting IIS default page when I stop my application.

I am using mvc3, razor application.

like image 471
Nutan Jayavant Avatar asked Nov 28 '11 08:11

Nutan Jayavant


People also ask

Where do I put httpErrors in web config?

You can configure the <httpErrors> element at the server level in the ApplicationHost. config file and at the site and application level in the appropriate Web. config file.

What is the difference between customErrors and httpErrors?

customErrors are a legacy (backwards compatable) element, used by Visual Studio Development Server (aka. VSDS or Cassini). httpErrors are the new element which is only used by IIS7. This highlights the possible problem when developing ASP.NET websites while using VSDS instead of the local IIS.

What are IIS error pages?

When there is an error page thrown in IIS (like 404 for example) it can expose relative or absolute paths on the Kaseya server. This is a security concern so a good security practice is to hide those paths to remote viewers as there is no need for them to see it.

How do I hide detailed error information for IIS and ASP Net?

To prevent unauthorized users from viewing this privileged information, detailed error pages must not be seen by remote users. This setting can be modified in the errorMode attribute setting for a Web site's error pages. By default, the errorMode attribute is set in the Web.


2 Answers

It took me a while to figure this out... but I think this might help you:

First of all to configure errors in IIS 7 you need to do it using the following section:

  <system.webServer>
    <httpErrors existingResponse="Replace" defaultResponseMode="Redirect" errorMode="Custom">
      <remove statusCode="503"/>
      <error statusCode="503" responseMode="Redirect" path="Views/Shared/IISError.htm"/>          
    </httpErrors>
  </system.webServer>

This configuration works, however you might receive an error indicating that you cannot override the httpErrors section, if that's the case, follow the next steps:

  1. Open the C:\Windows\System32\inetsrv\config\applicationHost.config

  2. Change:

    <section name="httpErrors" overrideModeDefault="Deny" />
    

    To:

    <section name="httpErrors" overrideModeDefault="Allow" />
    
like image 59
Jupaol Avatar answered Nov 09 '22 13:11

Jupaol


The question is, are you using VisualStudio Development Server or IIS7 Express ?

if you are using Cassini (VSDS) then you should try with

<customErrors mode="On" >
  <error statusCode="503" redirect="/Views/Shared/Error.htm"/>
</customErrors>

because httpErrors is a new structure that is handled only by IIS7. You can find some more info on : What is the difference between customErrors and httpErrors? and http://www.iis.net/ConfigReference/system.webServer/httpErrors

like image 37
Paweł Staniec Avatar answered Nov 09 '22 13:11

Paweł Staniec