Response.Redirect Method

Response is object of HttpResponse class and Redirect method of the HttpResponse class

2.    Respone.Redirect method first sends request for new page to web browser then web browser sends this request to web server then web server sends to response web browser and page change.

3.    Response.Redirect method  can be use for redirect on any type of pages like .aspx,.html,.pdf etc from .aspx page.

4.    Response.Redirect  method changes url of web browser.

5.    Response.Redirect is two overloaded method.

  (i) Response.Redirect("home.aspx"); //url of new page

  (ii) Response.Redirect("home.aspx", false);/*first parameter url of page,

                                   second parameter for endResponse*/

6.    When use Response.Redirect method a ThreadAbortException exception occurs.

7.    Response.Redirect  method call Response.End internally.

Problem :

When Response.Redirect method call in try block  then catch block excute and exception write in log file means extra code will be excute.

try

            {

                Response.Redirect("home.aspx"); //url of new page

            }

            catch(Exception ee)

            {

                Response.Write(ee.Message);

            }

Above code catch block excute and give Exception :

“ Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.”

Solution :

Response.Redirect method excutes after that should not excute Response.End method. For this Response.Redirect method second parameter set false so that Response.Redirect  method not internal call of Response.End method.

try

          {

             Response.Redirect("home.aspx", false);/*first parameter url of       

page,second parameter for endResponse*/

}

            catch(Exception ee)

            {

                Response.Write(ee.Message);

            }

Here catch block does not call.