10

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 http://learn.iis.net/page.aspx/145/how-to-use-locking-in-iis-70-configuration ( Task 2 )

by adding location tag in the Web.config

as following

<configuration>
....
....

  <location  allowOverride="true">
        <system.webServer>
            <httpErrors existingResponse="PassThrough" />
        </system.webServer>
  </location>
</configuration>

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

Update:

I am able to get rid of the locked error

if i modify applicationHost.config file and change

this

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

to

<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

3
  • Did you happen to try exisitingResponse="Replace" instead of "PassThrough"? Nov 28, 2011 at 21:03
  • Just for Google; the German error message reads Dieser Konfigurationsabschnitt kann in diesem Pfad nicht verwendet werden. Dies ist der Fall, wenn der Abschnitt auf übergeordneter Ebene gesperrt ist. Die Sperrung erfolgt standardmäßig (overrideModeDefault="Deny") oder wird explizit mit einem location-Tag mit overrideMode="Deny" oder der Legacyeinstellung allowOverride="false" festgelegt..
    – Uwe Keim
    May 19, 2014 at 9:31
  • 1
    is it possible use configSource with httpErrors ?
    – Kiquenet
    Jul 1, 2015 at 11:59

1 Answer 1

3

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;
                Response.Clear();
                Server.ClearError();
                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);
                errorsController.Execute(rc);

        }

Controller:

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.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.