Can't set 403 status?

S

Steve - DND

When certain conditions are met on my ASPX pages, I want to set the status
of the response to 403, and have it handled by the custom 403 page I have
specified in my web.config file. Unfortunately it's not working. In my ASPX
page I have:

....
Response.StatusCode = 403;
....

In my web.config, I have:

<customErrors mode="On">
<error statusCode="403" redirect="403.aspx"/>
<error statusCode="404" redirect="404.aspx"/>
</customErrors>

If I do a Response.Write(Response.StatusCode) it says that it's 403, but I
never get redirected to the custom 403 page, it just continues loading the
page normally. Any thoughts?

Thanks,
Steve
 
P

Pooran Prasad

Hi Steve,
In the Internet Service Manager MMC, right-click the Web
site, and then select Properties.
Click the Custom Errors tab.
Choose the 403 HTTP error.
Edit Properties and give the file you want to display
Click OK, and then click Apply.

Hope that helps
Have a great day :)
R. Pooran Prasad
Itreya Technologies Pvt Ltd.,
Mail: (e-mail address removed)
Phone(Off) : +91 80 5200179 Extn: 42
Mobile: +91 98860 29578
 
S

Steve - DND

I know how to change it via the IIS snap-in, but what I'm wondering is why
it doesn't work through the web.config file? Isn't the idea behind being
able to specify error redirects in the customErrors block, that you *don't*
have to use the IIS snap-in?

Steve
 
S

Steve - DND

I should also note that this is all irrelevant, since even though I'm
setting Response.StatusCode = 403, I'm still getting my normal ASPX page
returned, *not* my custom one, and *not* the IIS default 403 handler.

Steve
 
Joined
Nov 6, 2006
Messages
1
Reaction score
0
Make sure you ...

Set the mode="On" in the web.config

eg
<customErrors mode="On" defaultRedirect="defaultError.htm">
<error statusCode="404" redirect="404.aspx" />
<error statusCode="403" redirect="403.aspx" />
</customErrors>


Then in your code you can set response.status = xxx

hth,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top