NameValueCollection.AllKeys.Contains始终返回false

时间:2017-09-07 14:06:32

标签: c# namevaluecollection

System.Web.HttpContext.Current.Request.Params.AllKeys.Contains(key)

始终返回false,但

System.Web.HttpContext.Current.Request.Params[key]

返回键的值。

有人能告诉我为什么会这样吗?

就我而言,键是" ctl00 $ ContentPlaceHolder1 $ username",我在System.Web.HttpContext.Current.Request.Params.AllKeys和System.Web.HttpContext中调试并检查了它。 Current.Request.Params,确切的密钥存在。

1 个答案:

答案 0 :(得分:2)

使用不区分大小写的字符串比较器初始化Params集合。当您使用Contains时,您没有提供任何比较器,因此您使用默认设置,这将使用区分大小写的比较。