title: HttpUtility.UrlEncode and Application_Start
body: <p>As per <a href="http://ayende.com/blog/4599/hunt-the-bug" rel="nofollow noreferrer">http://ayende.com/blog/4599/hunt-the-bug</a>, I've run into one of those scenarios whereby "Response is not available in this context".</p>
  
  <p>Greatly simplified, the following throws an exception in certain scenarios on Windows Server 2008/IIS7/ASP.NET 4.0</p>
  
  <pre><code>public class Global : HttpApplication
  {
         public void Application_Start(object sender, EventArgs e)
         {
              HttpUtility.UrlEncode("Error inside!");
         }
  }    
  </code></pre>
  
  <p>The solutions that I've seen involve one of the following:</p>
  
  <ol>
  <li>Do as Ayende did and "write my own HttpUtility (well, take the one from Mono and modify it) to avoid this bug."</li>
  <li>or determine whether using HttpEncoder.Default instead does the trick. I'm trying to track down how best to do this.</li>
  <li>or use Uri.EscapeDataString as per <a href="https://stackoverflow.com/questions/602642/server-urlencode-vs-httputility-urlencode/1148326#1148326">Server.UrlEncode vs. HttpUtility.UrlEncode</a></li>
  </ol>
  
  <p>Maybe it's not my best googling day, but how to implement HttpEncoder.Default? </p>
  
  <p>Recommendations?</p>