How to override HttpErrors section in Web.Config - ASP.NET MVC3


I am trying to add custon 404 pages as per answer of this question

ASP.NET MVC 404 handling and IIS7 <httpErrors>

by adding

<httpErrors existingResponse="PassThrough" />

under <system.webServer> tag in my Web.Config file.

But I am getting following error

Module: CustomErrorModule 
Notification: SendResponse 
Handler: System.Web.Mvc.MvcHandler 
Error Code: 0x80070021 
Config Error: This configuration section cannot be used at this path. 
              This happens when the section is locked at a parent level. 
              Locking is either by default (overrideModeDefault="Deny"), 
              or set explicitly by a location tag with overrideMode="Deny" 
              or the legacy allowOverride="false".  

 Config Source
  153:       <httpErrors existingResponse="PassThrough" />
  154:   </system.webServer>

I also tried to override the locking based on ( Task 2 )

by adding location tag in the Web.config

as following


  <location  allowOverride="true">
            <httpErrors existingResponse="PassThrough" />

but I am getting the same error.

How should I configure httpErrors element in Web.config so it works

I am using IIS 7 , VS 2010 , ASP.NET MVC3


I am able to get rid of the locked error

if i modify applicationHost.config file and change


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


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

but ideally I do not want to change applicationHost.config file and want to override it from the Web.config file
asked on Stack Overflow May 17, 2011 by N30 • edited May 23, 2017 by Community

1 Answer


If you are interested you can create custom errors handling from your Global.asax.cs:

protected void Application_Error()

                var exc = Server.GetLastError();
                var httpExc = exc as HttpException;
                var routeData = new RouteData();
                routeData.Values["controller"] = "Error";
                routeData.Values["action"] = "General";
                routeData.Values["exception"] = exc;
                Response.StatusCode = 500;
                if (httpExc != null)
                    Response.StatusCode = httpExc.GetHttpCode();
                    routeData.Values["action"] = "Http404";
                    routeData.Values["exception"] = httpExc;
                Response.TrySkipIisCustomErrors = true;
                IController errorsController = new WWS_Website.Controllers.ErrorController();
                var rc = new RequestContext(new HttpContextWrapper(Context), routeData);



public ActionResult General(Exception exception)
  return View(exception);

public ActionResult Http404(Exception exception)
  return View(exception);

You can have different views for each error. You can also send email from this controller method to you webmaster email account - very handy.

answered on Stack Overflow Dec 6, 2011 by bobek

User contributions licensed under CC BY-SA 3.0