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?)
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.
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.
Redirect() is used for redirection.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With