Httperrors in web.config

I try to use a simple html page when a message arrives about a broken service 503.

I use below in web.config system.webservers

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

It works. I still get the default IIS page when I stop my application.

I am using the mvc3 razor app.

+5
source share
4 answers

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

First of all, to configure errors in IIS 7, you need to do this 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>

, , , httpErrors, , :

  • C:\Windows\System32\inetsrv\config\applicationHost.config

  • :

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

    To:

    <section name="httpErrors" overrideModeDefault="Allow" />
    
+7

, VisualStudio Development Server IIS7 Express?

Cassini (VSDS),

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

httpErrors - , IIS7. : customErrors httpErrors? http://www.iis.net/ConfigReference/system.webServer/httpErrors

+2

, , .

, web.config. IIS.

+1

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

WITH#:

[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>
+1
source

All Articles