隐藏查询字符串参数,怎么样? [英] Hide a QueryString parameters, how?
问题描述
我有一个网址:像这样的: HTTP://www.example/about/49
的 。结果
我希望它被视为 HTTP://www.example/about/
的,但我必须有这个作为传递参数的 查询字符串
的参数。
I have a url: like this one: http://www.example/about/49
.
I want it to be seen as http://www.example/about/
, but I must have this parameters passed as QueryString
parameters.
这可能吗?
推荐答案
小心会话变量;很容易有多个页面它们都使用同一个会话打开,并最终混合值。
Be careful with session variables; it's easy to have multiple pages opened which are all using the same session and end up mixing the values.
这将是更好地使用的TempData code>,只允许使用一次的值(第一次访问删除)。然而,这意味着该值将几乎立即使用。
It would be better to use TempData
, which only allows the value to be used once (removed on first access). However, this implies the value will be used almost immediately.
您也可以写一个cookie的期望值,拦截请求(ASP.Net提供了多种这样的方式,如的BeginRequest
事件)并在内部处理,就好像它包含的值的URL。
You can also write a cookie with the desired value, intercept the request (ASP.Net provides a variety of ways of doing this, such as the BeginRequest
event), and internally process the URL as though it contained the value.
当然,你再要清除该Cookie(这将有同样的问题,作为一个基于会话的解决方案)。请记住,Cookie是更容易被篡改的客户端。
Of course, you then must cleanup the cookie (which will have the same problem as a Session-based solution). Remember that a cookie is more vulnerable to tampering on the client.
我个人认为,任何一种方法都远远更多的麻烦比他们的价值。 破解的网址的(如那些含有一种潜在的有意义的ID )是通常的好的事情。
Personally, I think any of these approaches are far more trouble than they are worth. "Hackable URLs" (such as those which contain a potentially meaningful ID) are usually a good thing.
这篇关于隐藏查询字符串参数,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!