Global Redirect

S

Smithers

How can I cause all requests for [pages that no longer exist in a Web site]
to result in the user receiving default.aspx?

Thanks!
 
K

Ken Cox [Microsoft MVP]

You're looking for a 404 error handler.

http://www.dotnetjohn.com/articles.aspx?articleid=42

<configuration>
<system.web>
<customErrors mode="on"
defaultRedirect="customerrors.aspx?err=Unspecified">
<error statusCode="404"
redirect="customerrors.aspx?err=File+Not+Found"/>
</customErrors>
</system.web>
</configuration>


A Google search will turn up several techniques including these:

http://www.aspemporium.com/tutorials.aspx?tid=15

http://www.startvbdotnet.com/aspsite/forms/debug.aspx

Setting Status Code Errors

While browsing the Internet you might have come across these kind of error
messages, Page not Found, You are Not Authorized to View this page, HTTP
Error 404 - File or directory not found, etc. This type of errors are called
as status code errors and you can set these kind of errors in the ASP.NET
Web.Config file. The type of error will be identified by the HTTP status
code. The Web.Config file for that looks like this:

<configuration>
<system.web>
<customErrors mode="RemoteOnly"
DefaultRedirect="http://startvbdotnet.com/Error.aspx"/>
<error statuscode="404"
redirect="http://startvbdotnet.com/errorpages/notfound.aspx"/>
<error statuscode="403"_
redirect="http://startvbdotnet.com/errorpages/notauthorized.aspx"/>
</customErrors>
</system.web>
</configuration>
 
R

recoil

In your Web.Config you can handle it as such

<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly">
<error statusCode="404"
redirect="Default.aspx"/>
</customErrors>
This should be added to he System.Web or merged with existing markup.

It hsould be noticed that this will only work for files that asp.net is
handling. Meaning if somebody requests bleah.html it will use the
default IIS 404 handler.

In order to get this behavior for all files you should set a custom 404
handler through IIS for that application/website.
This may or may not be offered by your web hosting company if you are
hosting with a ISP and you should contact them regarding this if so.
 

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
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top