Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
I want ReWrite Url By Asp.net in Web.Config For Example change This Url : http://localhost:33862/User/DetailAgahy?Id=148 To Url : http://localhost:33862/User/DetailAgahy/Id/148
Posted

1 solution

Hello.

You should use urlrewritingnet, UrlRewritingNet.UrlRewrite tool. It allows to redirect from request like this: http://www.windevpowertools.com/ToolPage.aspx?ToolID=12 to this http://www.windevpowertools.com/Tools/12 , and vise - versa. This tool is using regular expression to catch up an ID or other parameter from original, requested URL and path it to real server URL.
For example, this is the rule:
XML
<add virtualurl="~/User/DetailAgahy?Id=(\d+)">
    destinationUrl="~/User/DetailAgahy/Id/$1"
    ignoreCase="true" /></add>


(\d+) - is taking number value into params collection, later you can reference it as $1.
So in each place, where you have numbers (IDs) in the original URL, you specify this (\d+) and than you can reference it in the destination URL this way $1, $2, $3 .... I've used this technique at one of my projects, confirmed that it is working smoothly. Enjoy!

More details and examples:
http://www.razafayyaz.com/2013/06/extensionless-url-rewrite-in-aspnet.html[^]

http://www.developer.com/net/article.php/3703901/How-to-Implement-and-Utilize-URL-Rewriting-with-ASPNET.htm[^]

Hope it helps!
 
Share this answer
 
v2

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