C# 为什么Request.QueryString.Get()和NameValueCollection.Get()返回解码值?

C# 为什么Request.QueryString.Get()和NameValueCollection.Get()返回解码值?,c#,asp.net,C#,Asp.net,我在从查询字符串中提取值的几行代码中观察到一些奇怪/未预料到的行为 函数调用 ValidateRequestNameValueCollection(HttpContext.Current.Request.Headers // other params omitted 函数定义 private void ValidateRequestNameValueCollection(NameValueCollection nvc, // other params omitted {

我在从查询字符串中提取值的几行代码中观察到一些奇怪/未预料到的行为

函数调用

ValidateRequestNameValueCollection(HttpContext.Current.Request.Headers // other params omitted
函数定义

 private void ValidateRequestNameValueCollection(NameValueCollection nvc, // other params omitted
        {
            int count = nvc.Count;

            validationFailureIndex = 0;

            for (int index = 0; index < count; ++index)
            {
                string key = nvc.GetKey(index);

                if (null != key && key.StartsWith(DoubleUnderline, StringComparison.Ordinal))
                    continue;

                string str = nvc.Get(index); // this is returning a decoded string
private void ValidateRequestNameValueCollection(NameValueCollection nvc,//省略了其他参数
{
int count=nvc.count;
validationFailureIndex=0;
对于(int index=0;index
在visual studio调试器中,如果我将鼠标悬停在NameValueCollection参数上,我会看到类似以下内容:

{param=ommitted3gcdqhrqg5w%2b6NJfc%3d}

这显然是编码的,但是当调用
.get
时,返回的字符串会被解码。根据这里的答案:我认为
NameValueCollection
参数被愚蠢地强制转换为
HttpValueCollection
,并且
HttpValueCollection
会在get.I上自动调用
UrlDecode
但是,找不到任何明确说明此问题的文档。有人知道吗?

请参阅或


这有什么关系?你知道它确实返回一个解码值。答案是“这就是它的编程方式”。如果你想知道为什么它是这样编程的,请询问Microsoft的某个人。只是意识到这对HttpValueCollection的如何/为什么/何时/是否有无声转换没有帮助…我会特别留意。这太完美了!希望将来能帮助其他人。
internal void FillFromString(String s, bool urlencoded, Encoding encoding) {
    ...
    if (urlencoded)
        base.Add(
            HttpUtility.UrlDecode(name, encoding),
            HttpUtility.UrlDecode(value, encoding));
    else
        ...