Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Please help in clarifying the following.

I have a project in which I am redirecting pages having Query String values in it. eg:

www.codeproject.com/product.aspx?bookid=5&bookname=23

Now, I want to implement URL Routing technique onto my project. So that the URL should look like the following:

www.codeproject/Product/5/23

I have created Route Definition in global.asax file.For the purpose of testing, When I run my project and change the old by myself URL from "href="http://www.codeproject.com/product.aspx?bookid=5&bookname=23 " to my required url " www.codeproject/Product/5/23 ". It works fine.

But My question is :

My old url still comes up ugly having Query String values in it. I want them to automatically appear like " www.codeproject/Product/5/23 " or " www.codeproject/Product/7/34 "

I don't want to change the url all the time. I want the url to appear in the above format automatically.

Do I need to change all the c# code of server.redirect to the required format now or their is any other technique which transforms the ugly url to good looking, meaningful and readable format.


many thanks,
Jass
Posted
Updated 11-May-11 21:08pm
v3
Comments
AspDotNetDev 11-May-11 0:02am    
I recommend just accept the ugly URL's in your development environment. You could create some redirect rules that check the Request.RawUrl and redirect to a clean URL if an ugly URL is detected, but that seems like more trouble than it's worth.
ZeeroC00l 12-May-11 2:29am    
Please remove the <pre> tags from your Question. They are supposed to be used only with the Code Segmentes :)
Jass22 12-May-11 2:42am    
ZeeroC00l , thank you for help.
Where is <pre> tag in my question plz?
Kind regards,
ZeeroC00l 12-May-11 3:04am    
It should be somewhere before "Hi" in your Question. Other wise the question wont be displayed like what its being displayed here.
Jass22 12-May-11 3:25am    
cheers

Checkout: IIS URL Rewrite[^].
 
Share this answer
 
is this new project? you might want to try MVC instead, it has all that you wanted.
 
Share this answer
 
Hello,

For this problem, I would recommend that you use a URL rewriter. It is quite easy, as you can see in my blog-post here: http://blog.dotnetcorner.ch/post/2011/03/30/How-to-Create-an-easy-and-flexible-URL-Rewriter.aspx[^].

The difficulty by using a URL Rewriter is, that you always need to know that you have two different URLs and that you never give out any internal (rewritten) URLs. So if you create a link, you have to concern about creating a "user-friendly" URL and not just write out the current Request.Url.

Hope this helps, happy coding! :)

Best regards,
Stops
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900