Parameter lost on Ajax post to MVC

Topics: Reverse Proxy, Rules
Jun 23, 2011 at 3:12 AM

Hi,

I have a site outside the firewall that I am using rewriter to map an intranet internal name to the external name. Gets work fine but an Ajax post from a jquery function fails due to the fact that no parameter is forwared to the MVC controller action.

When bypassing the proxy the call works fine, when using the proxy the call fails.

The call is: http://intranet/Controller/Action?id=1234 (anonymised)

The rule in rewriter is: RewriteRule ^/(.*) https://externaldomain/$1 [P]

At the web server the action does not get the id parameter and returns a 500 error.

Any pointers or help would be appreciated.

 

Jun 27, 2011 at 3:02 AM

Hi,

I solved it by putting this code in the beginning of SendRequest in ProxyHandler.cs. The code puts the query string parameters back in for the request on posts.

string uname = context.User.Identity.Name;
            string newUriString = string.Empty;
            Uri authUri = null;
            int i = context.Request.QueryString.Count;
            if (i > 0)
            {
                newUriString = RequestUrl.OriginalString + "?";
                foreach (string k in context.Request.QueryString.Keys)
                {
                    string val = context.Request.QueryString[k];
                    newUriString += k + "=" + val;
                    if (i > 0)
                        newUriString += "&";
                    i--;
                }
            }
            else
            {
                newUriString = RequestUrl.OriginalString;
            }
            authUri = new Uri(newUriString);
            var request = WebRequest.CreateDefault(authUri);