newme
newme

Reputation: 577

NameValueCollection.AllKeys.Contains always returns false

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.

Upvotes: 0

Views: 478

Answers (1)

Servy
Servy

Reputation: 203843

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.

Upvotes: 3

Related Questions