X-MicrosoftAjax header being stripped out by firewalls

Discussion in 'ASP .Net Web Controls' started by Chris Chamberlain, Sep 25, 2007.

  1. Hi,

    I am using the ms ajax library with an update panel in a user web control.
    The update panel contains two linked dropdownlists whose contents are
    modified (on autopostback) depending on the selection in eachother. This
    also modifies the imageurl of an image control, also in the same update
    panel.

    This works fine locally, but as soon as I host it on our webserver (outside
    our firewall) and access it from inside our firewall, it throws an error:
    "Sys.WebForms.PageRequestManagerParserErrorException: The message received
    from the server could not be parsed...". It works fine when called from a
    browser on the webserver itself.

    I have discovered this is down to our firewall stripping out the "unknown
    header" X-MicrosoftAjax, which is added to the web request by the
    ScriptManager during the postback. This causes the server to think it's a
    full-page postback and sends back the entire page in the response, not just
    the partial update. The page works fine when I remove the "unknown headers"
    filter from our firewall.

    This will also happen to other visitors who have similar filters on their
    firewalls and, I assume, must affect *every* website that uses ajax update
    panels.

    I have only found one solution so far for this, which involves BeginRequest
    in global.asax and requires adding the header back in to the collection if
    it is found to be missing on an ajax partial postback, (code below).

    However, I am receiving the error "Operation is not supported on this
    platform." at System.Web.HttpHeaderCollection.Add(String name, String
    value).

    Does anyone have any idea how to get around either of these problems?

    Kind regards

    Chris Chamberlain
    Head of IT
    VEF (UK) Ltd
    www.vefuk.com
    ------------------------------------------------------------------

    Code (found on http://forums.asp.net/p/1144748/1850717.aspx):

    On the page with the UpdatePanel...
    <script type="text/javascript>
    function beginRequest(sender, args) {
    var r=args.get_request();
    if (r.get_headers()["X-MicrosoftAjax"])
    {
    b=r.get_body();
    var a="__MicrosoftAjax=" +
    encodeURIComponent(r.get_headers()["X-MicrosoftAjax"]);
    if (b!=null && b.length>0)
    {
    b+="&";
    }
    else
    b="";
    r.set_body(b+a);
    }
    }
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
    </script type="text/javascript>

    And in BeginRequest (Global.asax or in an HttpHandler).....
    HttpRequest request = HttpContext.Current.Request;
    if (request.Headers["X-MicrosoftAjax"] == null &&
    request.Form["__MicrosoftAjax"] != null)
    {
    request.Headers.GetType().InvokeMember("MakeReadWrite",
    System.Reflection.BindingFlags.InvokeMethod |
    System.Reflection.BindingFlags.NonPublic |
    System.Reflection.BindingFlags.Instance, null, request.Headers, null);
    request.Headers.Add("X-MicrosoftAjax", request.Form["__MicrosoftAjax"]);
    request.Headers.GetType().InvokeMember("MakeReadOnly",
    System.Reflection.BindingFlags.InvokeMethod |
    System.Reflection.BindingFlags.NonPublic |
    System.Reflection.BindingFlags.Instance, null, request.Headers, null);
    }
     
    Chris Chamberlain, Sep 25, 2007
    #1
    1. Advertising

  2. Chris Chamberlain

    Sean Moran Guest

    Re: X-MicrosoftAjax header being stripped out by firew...

    Did you ever figure this out? I am having a similar problem and getting the same error message.

    Thanks,

    Sean
     
    Sean Moran, Oct 23, 2007
    #2
    1. Advertising

  3. Chris Chamberlain

    Sean Moran Guest

    Re: X-MicrosoftAjax header being stripped out by firew...

    Did you ever figure this out? I am having a similar problem and getting the same error message.

    Thanks,

    Sean
     
    Sean Moran, Oct 23, 2007
    #3
  4. Chris Chamberlain

    Guest

    On 25 Sep, 15:21, "Chris Chamberlain" <> wrote:
    > This will also happen to other visitors who have similar filters on their
    > firewalls and, I assume, must affect *every* website that uses ajax update
    > panels.


    Yes, but it is very uncommon that corporate firewalls strips headers
    for users accessing a site (outbound). It is way more common that a
    strip occurs on the way in to a server (inbound).

    > However, I am receiving the error "Operation is not supported on this
    > platform." at System.Web.HttpHeaderCollection.Add(String name, String
    > value).
    >
    > Does anyone have any idea how to get around either of these problems?
    > Code (found onhttp://forums.asp.net/p/1144748/1850717.aspx):


    The guy who posted that code has posted an update there that does not
    give that error message for me.

    It looked really promising until I got:
    Sys.WebForms.PageRequestManagerParserErrorException: The message
    received from the server could not be parsed...
    Details: Error parsing near 'sdfsdfsdfsdf=|64'.
    Where sdfsdfsdf is the end of the ViewState.

    Analyzing the responses from the server, first going through the
    firewall and then while accessing the site directly I notice some
    small differences.

    This a part of the response for direct connection:
    Content-Type: text/plain; charset=utf-8

    1c3a5
    115566|updatePanel|ctl00_mainPlaceHolder_UpdatePanel2|

    and this is while going through the firewall/proxy:
    Content-Type: text/plain; charset=utf-8

    115566|updatePanel|ctl00_mainPlaceHolder_UpdatePanel2|

    Somehow 1c3a5 has been removed. If anyone of you can tell my why or
    even what 1c3a5 is in this context you would make my day.

    Also if you do have another solution to the problem with firewalls
    stripping the x-microsoftajax header that would also be very
    interesing.
     
    , Nov 8, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karl Seguin

    firewalls "removing bogus header"

    Karl Seguin, Feb 10, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,409
    George Ter-Saakov
    Feb 10, 2004
  2. Guramrit Singh
    Replies:
    1
    Views:
    437
    bruce barker
    Jul 16, 2008
  3. Abro Gaticus

    XML::LibXSLT element tags stripped out

    Abro Gaticus, Mar 22, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    138
    Abro Gaticus
    Mar 23, 2005
  4. Simon Wigzell

    Javascript in emails being stripped

    Simon Wigzell, Feb 15, 2005, in forum: Javascript
    Replies:
    10
    Views:
    174
    John W. Kennedy
    Feb 17, 2005
  5. geed_dd
    Replies:
    2
    Views:
    138
    geed_dd
    Jun 8, 2006
Loading...

Share This Page