How to automatic redirect the wrong URL to the specific page?

A

ABC

If I has a web site which contains follows maps:

\default.aspx
\search.aspx
\products.aspx
\contacts.aspx

I should want to handle the unknow URL redirect to search.aspx to search.
For example, users enters the path as:

http:\\xxxxxxxx.com\P5GDLS

In my mind, P5GDLS is one of our products. When user entered above, I want
it redirect to search.aspx to search P5GDLS product information. I don't
this case naming, but I know some web sites can handle. How should I to
write the code to handle this case.
 
H

Hans Kesting

ABC said:
If I has a web site which contains follows maps:

\default.aspx
\search.aspx
\products.aspx
\contacts.aspx

I should want to handle the unknow URL redirect to search.aspx to
search. For example, users enters the path as:

http:\\xxxxxxxx.com\P5GDLS

In my mind, P5GDLS is one of our products. When user entered above,
I want it redirect to search.aspx to search P5GDLS product
information. I don't this case naming, but I know some web sites can
handle. How should I to write the code to handle this case.

You can't handle it completly within asp.net. As P5GDLS is not recognised
by IIS as something that should be handled by asp.net, that is never aware
of this request.
However, IIS itself will see that there is no file or directory with that name.
The usual result is a "404" warning, but you can instruct IIS to show a
specific page instead. So you could redirect "unknown page" errors
to a specific page within your application. If I'm not mistaken, you will
get the failed url as parameter, so then it's up to you to try and do
something with that.

Hans Kesting
 
G

Grant Merwitz

yeah, request.url should pickup what the attempted url was.
you can then strip of the "http:\\xxxxxxxx.com\" to get your product id, and
check if thats an existing product.
then redirect the user accordingly
 
K

KMA

I don't think you're right.

If you typed in p5gdls.aspx, then you get to find out the invalid url, but
if you type in plain p5gdls then IIS (as standard configuration) doesn't
pass onto the 404 page the originally requested url.

To help the user in this case (and where you can't configure IIS so that
ASP.NET handles all file extentions, including none) you should put a link
to your search page on your 404.

Of course, if you have access to configure IIS then you can take the
original request, pattern match for similar product IDs and present a list
of alternatives a la "Did you mean......".
 

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,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top