ASP.NET's Request.Form["key"]
collection uses a case-insensitive Comparer. This is screwing me up because I've got form POST data that looks like:
"subject=MySubjectLowerCase&Subject=MySubjectUpperCase"
As a result, Request.Form["subject"]
(or Request.Form["Subject"]
for that matter) return both values:
MySubjectLowerCase,Subject=MySubjectUpperCase
but what I want is the single value for my particular key, with case-sensitivity.
How can I change the Comparer to case-sensitive?
You cannot change the built-in comparer. However, if you are willing to parse the raw entity body, you can access it via HttpRequest.InputStream, GetBufferlessInputStream, or GetBufferedInputStream. The first two will make Request.Form inaccessible; the latter preserves Request.Form in case another piece of the request pipeline depends on it. This should be done only as a last resort as writing a parser can be a very tricky exercise.