I am working with URL rewriting, and have some issues. I want my url to be like this:
www.domain.com/product/myproduct
But I also want to be able to retrieve the ID of the product, without accessing the database. I thought about having a URL like:
www.domain.com/product/myproduct/1
or
www.domain.com/product/1-myproduct
But if I could hide the ID it would be better.
So, how do I do it the simplest way?
Currently my Global.asax has the following route:
routes.MapPageRoute("Produkt visning",
"legetoej/{Categoryname}/{SubCategoryname}/{ProductName}",
"~/SingleProduct.aspx");
And when I retrieve the name I do like this on SIngleProduct.aspx:
object productRoute = Page.RouteData.Values["ProductName"];
if (productRoute != null && !string.IsNullOrEmpty(productRoute.ToString()))
{
// do stuff
}
If I very simple could just get the ID instead of name, it would be awesome.
Thanks a lot awesome-stackoveflowers ;-)
To hide the ID of the Product... take the ID and apply Encryption to it... something like DES or Triple DES, then apply Server.URLEncode method to the ID and then you can easlily hide the id.
When you open the Page you can simple take the encrypted ID and do a Server.URLDecode and the decrypt the ID.
Anyways... why dont you pass the ID of the product as a get Parameter ? Something like... www.domain.com/product/myproduct?PID=#$$#12 , where the PID is encrypted and URL Encoded and then you can easily process it.