Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET: What happens to code after Response.Redirect(...)?

Does Response.Redirect() cause the currently running method to abort? Or does code after Response.Redirect() execute also?

(That is, is it necessary to return/Exit Sub after a Response.Redirect?)

like image 916
Brandon Avatar asked Aug 09 '09 22:08

Brandon


People also ask

Will code execute after response redirect?

When you use Response. Redirect("Default. aspx",true ) which is by default true then the execution of current page is terminated and code written after the Response. Redirect is not executed instead of executing code written after the Response.

What is response redirect in ASP NET?

Response. Redirect sends an HTTP request to the browser, then the browser sends that request to the web server, then the web server delivers a response to the web browser. For example, suppose you are on the web page "UserRegister. aspx" page and it has a button that redirects you to the "UserDetail.

Which of the following is used to redirect to different page without post back?

Redirect() is used for redirection.

How do I open a response redirect in a new tab?

When the Button is clicked, first the SetTarget JavaScript function is called inside which the target property of the Form is set to _blank and after that the Server Side function is executed. Inside the Button Click event handler, the Response. Redirect code is executed and the Page opens in new Tab.


1 Answers

Response.Redirect has an overload accepting a boolean argument that indicates if the call to Response.Redirect should end the response. Calling the overload without this argument is the same as specifying true to indicate that the response should end.

Ending the reponse means that Response.End is called after the response has been modified to make the redirect happen, and Response.End throws an ThreadAbortException to terminate the current module.

Any code after a call to Response.Redirect is never called (unless you supply false for the extra argument). Actually, code in finally and certain catch handlers will execute, but you cannot swallow a ThreadAbortException.

like image 168
Martin Liversage Avatar answered Oct 15 '22 10:10

Martin Liversage