Web forms and URL rewriting: Hide ID, show name?

余生颓废 提交于 2019-12-24 11:17:45

问题


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 ;-)


回答1:


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.



来源:https://stackoverflow.com/questions/10614847/web-forms-and-url-rewriting-hide-id-show-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!