Is there a way to specify which string comparison to use on a site-wide level?
<p>The reason I ask is because I just found a really weird bug that only happened on our production box. Here is a small example:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{
    ...
    var form = Request.Form;
    string name = form.GetValueOrDefaultIfKeyExists("firstName");
    string email = form.GetValueOrDefaultIfKeyExists("emailAddress");
    ... 
}
</code></pre>

<p>On our production box - name and email would be String.Empty after this code ran - even though the form contained keys with 'firstName' and 'emailAddress'. The <code>GetValueOrDefaultIfKeyExists</code> is a custom extension method, implemented this way:</p>

<pre><code>public static Boolean HasKey(this NameValueCollection collection, String key)
{
    return collection.AllKeys.Any(x =&gt; x.Equals(key));
}

public static String GetValueOrDefaultIfKeyExists(this NameValueCollection collection, String key)
{
    return GetValueOrDefaultIfKeyExists(collection, key, String.Empty);
}

public static String GetValueOrDefaultIfKeyExists(this NameValueCollection collection, String key, String defaultValue)
{
    return collection.HasKey(key) ? collection[key].Trim() : defaultValue;
}
</code></pre>

<p>The problem was with the <code>HasKey()</code> method on our production box. This returned false on our production box until i changed it to this implementation:</p>

<pre><code>public static Boolean HasKey(this NameValueCollection collection, String key)
{
    return collection.AllKeys.Any(x =&gt; x.Equals(key, StringComparison.OrdinalIgnoreCase));
}
</code></pre>

<p>Does anyone have a possible explanation for the difference in behavior? Both the dev and production boxes are using IIS6.0 and asp.net v2.0. I'm not really sure what else to look at here...</p>

<p>edit: when i run the page on localhost and dump the variables to the page by just looping over the Request.Form key/values, i get output like this:</p>

<pre><code>__VIEWSTATE = /wEPDwUJNTE2ODkwODQ2ZGS2XnJpbO5ngrJFByrGtuNn3PkU5A==

LandingPage = ~/Newsletter/thank-you.aspx

SourceDesc = 676

emailAddress = bntest222@test.com

confirmEmailAddress = bntest222@test.com

firstName = mtest

postalCode = 23320
</code></pre>

<p>the same code run on our production box dumps this:</p>

<pre><code>__viewstate = /wEPDwUJNTE2ODkwODQ2ZGSWeuNU+/5eQHvpsMc66Ayh4lEdWQ==

confirmemailaddress = mtest332@test.com

emailaddress = mtest332@test.com

firstname = mtest

landingpage = ~/Newsletter/thank-you.aspx

postalcode = 23320
</code></pre>

<p>it looks like the keys are being lower-cased... why?</p>
