vanity URLs (2nd time)

S

Stimp

sorry I have to repost this question since I can't find the
replies (if any) to a question I posted two days ago
(what's the post turn-around for this group btw, every 2 days
they delete all posts in cache or something?)

If a browser to my site enters:
http://www.website.com/user/123

I want this to automatically redirect to:
http://www.website.com/index.aspx?myuserid=123.


I know how to do this if you enter a URL like:
http://www.website.com/user/123.aspx (i.e. with a file extension)

and then in the global.asax BeginRequest method you can redirect the URL
to http://www.website.com/index.aspx?myuserid=123 using:

strCustomPath = _
String.Format( _
"/index.aspx?myuserid={0}", _
Path.GetFileNameWithoutExtension( Request.Path ) )
Context.RewritePath( strCustomPath )

Any idea how to do it without having to add a .aspx to the end of URL?

Cheers!
 
K

Ken Kolda

You can do this in the IIS Management Console as follows:

1) Create a new virtual root named "user" -- it doesn't matter where you
point it to for the time being.
2) Go the new virtual root's properties page and select the option "A
redirection to a URL"
3) In the "Redirect to" box, put "*;/*;/index.aspx?myuserid=$0"
4) Check the box that says "The exact URL entered above".

That's it -- it should redirect automagically when you hit the
/users/whatever URL. For more info on the redirection features in IIS, check
out

http://localhost/iishelp/iis/misc/default.asp?jumpurl=../htm/core/iiabdsk.htm

Ken
 
P

PL

Since global.asax won't run unless you request a file associated with
the aspnet isapi you need the fileextension.

However, there is a trick that can be used and that's to catch the 404 error
that the server generates and then determine where the user actually wanted to go.

This needs to be configured in IIS, what you do is have it configured to go to a certain
url like /redir.aspx on 404 error and then parse the querystring and determine where to redirect.

The incoming querystring will look something like ?404;http://www.domain.top/somepage.html
and the link in it tells you what was requested.

I've only seen this be used for subdomains where you have a "catch all" domain
setup in the dns and then have people enter url's like http://someuser.mydomain.com
and you want to map this to the actual user dir.

You could probably use something similar, there are some sideeffects to this technique,
the most obvious is that the server won't show the real 404 errors when you want it to.

I don't think you can catch the 404 error in asp.net, you'll get the same problem, it only
handles the extensions associated with the aspnet isapi.

PL.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top