Gotcha with HttpResponse.Redirect

HttpResponse.Redirect is used to redirect to another page using a 302 response code. It can be used in two modes. One terminates the thread immediately so that execution does not continue to the next line of code. The other version continues execution, but returns a 302 response. The latter version is the only one that works from asynchronous callbacks (at least when using Page.RegisterAsyncTask). I guess it doesn’t like threads being terminated out from under it. There’s on gotcha with HttpResponse.Redirect(url, false) though. It will actually render the page, so the 302 response may have a bunch of unwanted data. The solution is to call Page.Visiable = false after doing the redirect. This will avoid rendering any content for the page. Good catch on this one, Josh!

Skip to main content