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