Web表单和URL重写:隐藏ID,节目的名字吗? [英] Web forms and URL rewriting: Hide ID, show name?

查看:238
本文介绍了Web表单和URL重写:隐藏ID,节目的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与URL重写工作,并有一定的问题。我想我的网址是这样的:

I am working with URL rewriting, and have some issues. I want my url to be like this:

www.domain.com/product/myproduct

但我也希望能够检索产品的ID,而无需访问数据库。我想过有像网址:

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 

www.domain.com/product/1-myproduct

但是,如果我能隐藏ID会更好。

But if I could hide the ID it would be better.

那么,我该怎么做最简单的方法是什么?

So, how do I do it the simplest way?

目前我的Global.asax有以下途径:

Currently my Global.asax has the following route:

routes.MapPageRoute("Produkt visning",
                        "legetoej/{Categoryname}/{SubCategoryname}/{ProductName}",
                        "~/SingleProduct.aspx");

而当我取回的名字我不喜欢这样的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
}

如果我很简单,可能只是获得ID,而不是名称,这将是真棒。

If I very simple could just get the ID instead of name, it would be awesome.

非常感谢真棒,stackoveflowers; - )

Thanks a lot awesome-stackoveflowers ;-)

推荐答案

要隐藏产品的ID ......走ID和应用加密它...像DES或三重DES,然后应用Server.URLEn code方法的ID,然后你可以easlily隐藏标识。

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.

当你打开页面就可以简单的把加密ID,做一个Server.URLDe code和解密的ID。

When you open the Page you can simple take the encrypted ID and do a Server.URLDecode and the decrypt the ID.

反正...你为什么不通过产品的ID作为GET参数?就像是...
www.domain.com/product/myproduct?PID=#$$#12,其中PID是加密的,URL连接codeD,然后你可以轻松地处理它。

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.

这篇关于Web表单和URL重写:隐藏ID,节目的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆