5

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.

Nutan Jayavant
  • 121
  • 1
  • 4

4 Answers4

8

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" />
    
Jupaol
  • 21,107
  • 8
  • 68
  • 100
2

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

Community
  • 1
  • 1
Paweł Staniec
  • 3,151
  • 3
  • 29
  • 41
  • How are you getting you IIS to throw 503? If you're doing it through the application it will go through Asp.Net handler. httpErrors directive is for content that does not go through Asp.Net – Paweł Staniec Nov 28 '11 at 13:24
  • I am stopping my app pool in IIS. this shows me default 503 page instead of my page. – Nutan Jayavant Nov 29 '11 at 06:01
  • If you are stopping your app pool you cannot set the custom error in the web.config. You will need to do it in IIS. – Eben Roux Jul 19 '12 at 06:08
1

Based on one of your comments it appears as though you are stopping your app pool.

If you are stopping your app pool you cannot set the custom error in the web.config. You will need to do it in IIS.

Eben Roux
  • 12,983
  • 2
  • 27
  • 48
1

In Mvc 5.1.1 and IIS 7.5, backslashes are required to indicate subfolders for File response mode.

C#:

[HttpGet]
[AllowAnonymous]
public ActionResult Login()
{
    try
    {
        var allowLogin = false;

        if(allowLogin == false)
            return new HttpStatusCodeResult(403);
    }
}

Web.config:

<system.web>
  <!--customErrors tag is not required -->
</system.web>
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="File" >
  <remove statusCode="400" subStatusCode="-1" />
  <remove statusCode="401" subStatusCode="-1" />
  <remove statusCode="403" subStatusCode="6" />
  <remove statusCode="403" subStatusCode="-1" />
  <remove statusCode="503" subStatusCode="-1" />
  <remove statusCode="500" subStatusCode="-1" />
  <clear/>
  <error statusCode="400" subStatusCode="-1" path="ErrorPages\400.html" />
  <error statusCode="401" subStatusCode="-1" path="ErrorPages\401.html" />
  <error statusCode="403" subStatusCode="6"  path="ErrorPages\Restrict.html" />
  <error statusCode="403" subStatusCode="-1" path="ErrorPages\403.html" />
  <error statusCode="503" subStatusCode="-1" path="ErrorPages\503.html" />
  <error statusCode="500" subStatusCode="-1" path="ErrorPages\500.html" />
</httpErrors>
Y P
  • 594
  • 8
  • 10