确实的Request.QueryString自动链接去code字符串? [英] does Request.Querystring automatically url decode a string?
问题描述
我与一个网页,我有一个url像工作:结果
/目录/公司/制造商
I'm working with a page where I have a url like:
/directory/company/manufacturer
使用这个被重新写了一些重写规则
Using some re-write rules this gets re-written
与/目录/公司测试/邓肯%26donuts /
testing with /directory/company/dunkin%26donuts/
一些制造商在他们的名字的符号。所以我想我可能只是替换 26%,与号
。然而,当我调试code和悬停在的Request.QueryString
它显示我 {QQ =公司和放大器; MANF =邓肯和放大器;甜甜圈&安培; COND =}
和的Request.QueryString [MANF]
给我'邓肯
Some manufacturers have an ampersand in their name. So I thought I could just replace the ampersand with %26
. However, when I debug the code and hover over Request.QueryString
it shows me {qq=company&manf=dunkin&donuts&cond=}
and Request.QueryString["manf"]
gives me 'dunkin'
如果我用 24%
($),而不是符号,将鼠标悬停在的Request.QueryString
给我 {QS =公司和放大器; MANF =邓肯%24donuts&安培; COND =}
和的Request.QueryString [MANF]
给我邓肯甜甜圈$
If I use %24
($) instead of ampersand, hovering over Request.QueryString
gives me
{qs=company&manf=dunkin%24donuts&cond=}
and Request.QueryString["manf"]
gives me 'dunkin$donuts'
我不明白这里的不同行为。为什么它看起来就像一个符号链接恩codeD值获得德codeD你居然要求一个特定的键之前,但另一个URL-CN codeD的性格,像一个美元符号,只得到德codeD之后你居然要求特定键?
I don't understand the different behavior here. Why does it seem as though the url-encoded value for an ampersand gets decoded before you actually request a specific key, but another url-encoded character, like a dollar sign, only gets decoded after you actually request that specific key?
这是一个最近的变化?我一直以为的Request.QueryString [关键]
返回的实际文本而不先对其进行解码。或者它有一些做与URL重新写?
Is this a recent change? I always thought Request.QueryString[key]
returned the actual text without decoding it first. Or does it have something to do with url re-writes?
推荐答案
与%26
应该引起转义该值,所以的Request.QueryString [MANF]
将产生邓肯和放大器;甜甜圈
Replacing the ampersand with %26
should cause that value to be escaped, so Request.QueryString["manf"]
would yield dunkin&donuts
.
的<一个提问者href=\"http://stackoverflow.com/questions/561954/asp-net-urlen$c$c-ampersand-for-use-in-query-string\">this类似的问题最终意识到,在同一页上其他一些code结束了pre-解码他的&符号。难道你有类似的事情发生?也许一些JavaScript被发送到服务器之前解码 26%
成一个符号。尝试使用Firebug或Chrome的开发者工具,一看就知道是从浏览器发送实际的URL字符串。
The asker of this similar question ended up realizing that some other code on the same page ended up pre-decoding his ampersands. Is it possible that you've got something similar happening? Perhaps some javascript is decoding the %26
into an ampersand before sending it to your server. Try using Firebug or Chrome's developer tools to see the actual URL string that is being sent from the browser.
在这个问题再次看后,我意识到,你可能使用URL重写。 这篇文章描述了一个类似的问题,我不知道肯定有解决方案,但你可能要尝试双重编码与符号使用%2526
而不是%26
。
After looking at the question again, I realize that you're probably using a URL Rewriter. This post describes a similar problem, and I don't know of a solution for sure, but you may want to try double-encoding the ampersand using %2526
instead of %26
.
这篇关于确实的Request.QueryString自动链接去code字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!