0

I have a HttpHandler which is called from JavaScript using the XmlHttpRequest object. I want the HttpHandler to redirect the client if some condition is not met.

I've tried playing with context.Response.Redirect(@"http://www.stackoverflow.com"), but this just send the web page contents in the http requests response to the client.

Is there any way to redirect the client from within the HttpHandler itself? Or does this have to occur once the client receives the XmlHttpRequest response?

Thanks

adamwtiko
  • 2,865
  • 8
  • 39
  • 47

1 Answers1

1

XmlHttpRequest object will always honor redirects from server and will give you the html from the redirected page - this is as per W3C specs and cannot be controlled (see Prevent redirection of Xmlhttprequest).

So only way for you will be to return a response from HttpHandler (with status code 200 OK) that will indicate need to redirect and the url, on receiving response, you can use java-script to do actual redirect (if needed).

Community
  • 1
  • 1
VinayC
  • 47,395
  • 5
  • 59
  • 72