views:

307

answers:

2

Here's my web.config customErrors section (you'll notice I've switched the mode to 'On' so I can see the redirect on my localhost):

    <customErrors defaultRedirect="~/Application/ServerError.aspx" mode="On" redirectMode="ResponseRewrite">
        <error statusCode="403" redirect="~/Secure/AccessDenied.aspx" />
    </customErrors>

and here's the code that throws:

        Catch adEx As AccessDeniedException

              Throw New HttpException(DirectCast(HttpStatusCode.Forbidden, Integer), adEx.Message)

        End Try

and here's what I end up with:

alt text

Which is not my pretty AccessDenied.aspx page but it is a forbidden error page so at least I know my throw is working.

I've removed the entry for 403 in IIS (7.0) as a desperate last attempt and unsuprisingly that made no difference.

I've run out of ideas now so any suggestions will be gratefully appreciated!

A: 

In fact, your aspx page may not be executing at all.
Go to IIS. Go to your default website properties. Click on the Home Directory Tab Click the configuration button. Now, check if a .aspx page is registered there.

LymanZerga
Can you tell me exactly what you're asking me to check for? On my dev machine I've got IIS 7.0 on Vista and IIS's UI has changed beyond all recognition so your directions don't map to what I see in IIS
Just to add (as whilst I'm not sure but I suspect you might be taking something out of context from the error) this question is in the context of an existing live enterprise asp.net web app. I'm adding some extra security and can't get the redirect to a custom error page for a 403 to work. The site works fine apart from the fact that when this exception is thrown (as it will be in certain exceptional circumstances) it's not going to the error page (AcccessDenied.aspx)
Thanks for correcting my assumptions. Similar errors usually pop up when people try using .asp pages in context of a .net site. IIS complains with the same error and extra configuration needs to be created to handle .asp files. In your case, I would perhaps try to create a simple .html page and try redirecting to that and see what happens.
LymanZerga
A: 

You need to specify existingResponse="PassThrough" in the system.webServer section of the httpErrors element.

<configuration>
   <system.webServer>
       <httpErrors existingResponse="PassThrough" />
   </system.webServer>
</configuration>
Phaedrus
Well doing that changes things. I now get a 500 error!
Oh not what you originally posted then. Still getting error 500 anyway.