views:

107

answers:

4

hey guys, like the title says, how can i accomplish this sort of a rewrite as simple as possible? is it with httphandlers or perhaps the asp.net routing? i am using version asp.net 3.5.

the problem is that i want any other requests to be ignored, like requests to .aspx files, images, folders and such for example:

i want these to get handled:

site.com/john => site.com/profile.aspx?nick=john

site.com/mark => site.com/profile.aspx?nick=mark

site.com/fred => /site.com/profile.aspx?nick=fred

i DONT want these to get handled:

site.com/page.aspx

site.com/images/logo.jpg

your suggestions are appreciated :)

A: 

this

Request.Url.ToString()

gets you the url (if the page i found this on is correct, i don't use asp.net very often)

you can use some regex on this URL, maybe some kind of...

site\.com/([\w])+$

don't know how to read the capturing parts of regex with .net, there must be an appropriate object.

then send a redirect to the user, you should be able to do this using the appropriate Redirect-HTTP-Header. if i'm right, there is a similarly named collection in the Response-Object.

note that this implementation does not allow rewriting

site.com/john/some_other_param

if you have questions on how to implement this in detail, i'll try to research further

regards

Atmocreations
+1  A: 

Scott Guthrie has a great post about this. If you're running IIS7, it's super easy with the URL Rewrite module.

Robert S.
Robert, i am using IIS7 but i am very new to this rewriting and this project is very time pressing. Would you be able to give me few pointer how i can accomplish my task using the module you have mentioned? I would really appreciate it :)
A: 

I've used UrlRewriter.net in the past to do this. It works really well. You can configure it to only apply the rewrite rules if there is NOT an existing file that maps to the url (ie, real aspx pages or image files)

http://www.urlrewriting.net

Of course, if you're using IIS7 there is built in routing to do this.

Jason
A: 

Ok, it looks like i can do this with URL Rewrite module per Robert S. :)

Can anyone assist me with this for my above scenario? I have never used it...

Thanks

Kris, part of being a developer is trial and error, and a lot of reading. So go read, try to implement this the best you can, and then come back here with specific questions. No one wants to spoon feed.
Ryan