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."

First ever post

Hi,

Finally I arrived in the world of blogs.

Just to introduce, I have made this blog to describe tips and tricks, short code snippets and configuration settings which I found on net or discovered by my own working in late nights.

Also, Its all about .NET specially, C#, ASP.NET and SQL Server 2005.

Hopes will try my best to share knowledge I got by practicing .NET as working platform.

Welcome to my blog :)