Wednesday, December 12, 2007

Correct use of Response.Redirect method

Whenever a Response.Redirect or a Response.End is called, the Global_ReleaseRequestState is bypassed.

Instead, a ThreadAbortException is raised (as you may know) and then Application_EndRequest is raised directly.

Method:
HttpResponse.Redirect Method (String, Boolean)

Call to above method redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.

[C#]
public void Redirect( string url, bool endResponse );

Redirect calls End which raises a ThreadAbortException exception upon completion.

ThreadAbortException is a special exception that can be caught, but it will automatically be raised again at the end of the catch block.

"Specifying the second parameter as false solves the Response.Redirect problem. In fact, this is supposed to be the correct way of using Response.Redirect. The single parameter version supposedly is just a VB-legacy carry-over."

No comments: