Tuesday, 1 June 2010

Effects of a Bluecoat Proxy on ASP.NET

I originally started getting issues with an ASP.NET report viewer. In the server event logs I was getting the message – ‘Missing URL parameter: Name’. After looking in to this issue, it appears that the client computer was behind a Bluecoat proxy which seems to replace ‘&’ with ‘amp;’

So, if you have a URL containing multiple parameters, the proxy server messes up the URL.


Without a Bluecoat Proxy

www.domain.com/admin/reporting/ByUsername.aspx?UserID=54865&LessonID=NE-BLT

With a Bluecoat Proxy

www.domain.com/admin/reporting/ByUsername.aspx?UserID=54865amp;LessonID=NE-BLT

I got around this issue by using the following code in the Global.asax.cs file under Application_BeginRequest. It will find anything in the URL with 'amp;' and replace it with an '&'.

if (Request.ServerVariables["HTTP_X_BLUECOAT_VIA"] == null)
{
    //Do nothing
}
else
{
    //Replace 'amp;' with '&'
    HttpContext.Current.RewritePath(Request.Path + "?" +
    Request.QueryString.ToString().Replace(Server.UrlEncode("amp;"), "&"),    true);
}