ASP.NET/IIS rewriting 302 responses as 200

824 views Asked by At

I want to use Response.Redirect to redirect to a new URL containing query string values like so:

Response.Redirect("http://www.example.org/?key1=value1&key2=value2");

This returns the following response to the browser, causing it to request the new page:

{script:"window.location=\"http://www.example.org/?key1=value1&key2=value2\";"}

Unfortunately, IE11 and Google Chrome handle this differently. IE11 behaves as one might expect, however Chrome HTML-encodes this response, causing the browser to redirect to http://www.example.org/?key1=value1&key2=value2, which is obviously not what I want. How can I use Response.Redirect to behave as expected in both browsers?

Edit:

For clarity, the sequence of events is as follows:

  1. Click a button on the page, which POSTs a form to the server
  2. The server-side code runs, which includes a call to Response.Redirect.
  3. In response to the POST, the browser receives a 200 containing {script:"window.location=\"http://www.example.org/?key1=value1&key2=value2\";"}
  4. The browser makes a GET to the URL - either to the one shown in the response in the case of IE, or to the HTML-encoded version in the case of Chrome.

Edit2:

I've updated my code to explicitly do a 302 Redirect instead of using Response.Redirect however it still behaves the same way! The 302 gets replaced with the JS redirect somewhere along the line! Does anyone know of any settings anywhere (in code or in IIS) that might cause this behaviour? My new redirect code is:

private void ExplicitRedirect(string url)
{
    Response.StatusCode = 302;
    Response.RedirectLocation = url;
    Response.End();
}
1

There are 1 answers

0
MorayM On

This project uses Ext.Net which apparently alters the behaviour of Response.Redirect. Using Ext.Net's own Redirect method still uses JS instead of 302 but for some reason this method works as expected.