Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

The Request.Form is a NameValueCollection object. You will need to implement a customized IComparerInterface for it. You will find this useful: http://msdn.microsoft.com/en-us/library/system.collections.icomparer(v=vs.100).aspx

Having said that, tvanfosson is right that it's a bad idea to implement case sensitive parameter values.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top