defaultRedirect not working (ASP.Net 2.0)

G

Guest

I think I am missing something about how to redirect to a certain page when
404 errors occur. I want to redirect to a generic pagenotfound.aspx page. I
have the following in web.config:

<customErrors mode="RemoteOnly" defaultRedirect="/misc/pagenotfound.aspx">
</customErrors>

However, when I enter a non-existent URL I just get the default Page Not
Found error page - my pagenotfound.aspx file is not invoked (it works fine if
I enter the full URL of the http://www.mysite.com/misc/pagenotfound.aspx page
directly, so there is no issue with the page itself).

I have this working fine on an ASP.Net 1.1 site.

Any ideas on what I am doing wrong?

Thanks.
 
G

Guest

Hi,
you can try by putting tilde(~) before URL:
<customErrors mode="RemoteOnly" defaultRedirect="~/misc/pagenotfound.aspx">
</customErrors>
The tilde (~) in front of URLs means that these URLs point to the root of
your web application.
Better still try with absolute URL instead of Relative URL:
<customErrors mode="RemoteOnly"
defaultRedirect="http://www.mysite.com/misc/pagenotfound.aspx ">
</customErrors>
For more details refer below link:
http://aspnetresources.com/articles/CustomErrorPages.aspx
 
G

Guest

Thanks for the response, Manish. No, no joy I am afraid. I still get the
default 404 page. Do you know if there is anyway to trace that at least an
attempt was made to redirect to my error page? My guess is that the
"plumbing" isn't in place for some reason and there is actually no attempt to
call my page. Any way to validate this. I am afraid I have been stuck on this
issue for a day or two.

Thanks again,
 
G

Guest

Hi,
Try with mode="On"
<customErrors mode="On" defaultRedirect="/misc/pagenotfound.aspx">
</customErrors>
Why that ugly page is displaying is that you are viewing page on your local
host and mode is set to "RemoteOnly".You need to set mode to "On".
Description of different modes are:
On
Specifies that custom errors are enabled. If no defaultRedirect attribute
is specified, users see a generic error. The custom errors are shown to the
remote clients and to the local host.

Off
Specifies that custom errors are disabled. The detailed ASP.NET errors are
shown to the remote clients and to the local host.

RemoteOnly
Specifies that custom errors are shown only to the remote clients, and that
ASP.NET errors are shown to the local host. This is the default value.

Hope this helps.
 
G

Guest

I am not sure that's it, Manish. Whether I do this locally or remotely I
still get exactly the same behavior. I wish I could prove this but I have a
strong guess that no attempt is being made to invoke my pagenotfound.aspx
file. If everything is OK (web.config is correct, the page exists, etc) then
no error message should be displayed, regardless of what mode is used
(because the redirect to my page should kick in whether I am local or
remote), right?

Thanks.
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top