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);
}

6 comments:

  1. Great first article! sorted my problem. Thanks.

    ReplyDelete
  2. Hi Matt, I hope you get this message. I'm using SQL Reporting Services and I'm seeing this exact error with my clients that join my network from the Blue Coat Proxies.

    Since I don't have access to the Global.asax.cs file; how would I implement this?

    Thanks,

    ReplyDelete
  3. Hi Chris,

    Why do you not have access to the Global.asax file?

    I have found the following link which may help you - http://www.15seconds.com/issue/030522.htm

    I am not 100% sure how it would be implemented without looking at your code, but there should be another way.

    I will try and write an article over the next few days which will hopefully answer your question.

    Thanks

    ReplyDelete
  4. Hi,

    What if you have this problem, but also want ability to send encoded ampersand?

    Looks to me that your solution will change all amp; to & - even legitimate amp;

    ReplyDelete
  5. Fixed it for me too - many thanks.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete