NameValueCollection.AllKeys.Contains always returns false

474 Views Asked by At
System.Web.HttpContext.Current.Request.Params.AllKeys.Contains(key)

always returns false, but

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

returns the value of the key.

Could someone tell me why this is happening?

In my case, the key is "ctl00$ContentPlaceHolder1$username", I debugged and checked that in both System.Web.HttpContext.Current.Request.Params.AllKeys and System.Web.HttpContext.Current.Request.Params, the exact key existed.

1

There are 1 best solutions below

10
On BEST ANSWER

The Params collection is initialized with a case-insensitive string comparer. When you use Contains you're not providing any comparer, so you're using the default, which will use a case sensitive comparison.