Keith
Keith

Reputation: 155692

Custom error setting being ignored for locations denied in the web.config

In a ASP.Net 4 and MVC2 application we have an odd configuration error.

The web.config looks something like this:

<configuration>
    <location path="blockedpath">
        <system.web>
            <authorization>
                <deny users="*" />
            </authorization>
        </system.web>
    </location>
    <system.web>
        <customErrors mode="On" defaultRedirect="~/Error.aspx" />
    </system.web>
</configuration>

Visiting the blocked location is correctly denied, but gives a verbose error message from IIS that we don't want.

Why doesn't it serve up the configured custom error?

Can we control what page it does serve up when page access is denied by config?

Upvotes: 2

Views: 693

Answers (2)

Martin Buberl
Martin Buberl

Reputation: 47144

According to this blog post, IIS7 is trying to be helpful and likes to steal your custom errors pages and replace them with its own.

Open the Error Pages feature in IIS and click Edit Feature Settings on the right hand menu. Set the Detailed errors option to have IIS pass through whatever errors you serve up from ASP.NET.

Upvotes: 1

Kev
Kev

Reputation: 119806

If this is IIS7 then it looks like IIS is hijacking the response. Try this:

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

Upvotes: 0

Related Questions