I have a regular Asp.Net 4.0 webforms website. When I do:
Response.Redirect("SomePage.aspx");
I’d expect that my next line of code would be executed. However, surprisingly the next line of code is never executed. Can anybody know when and why does that happen?
Response.Redirectalso accepts two parameters. The second parameter which is a boolean denotes whether the execution of the current page should terminate.So, calling
Response.Redirect("Page.aspx",false)would execute the subsequent lines of code and will avoidThreadAbortExceptionbeing flooded in your log files.Update: To answer why the default behavior is to not execute
When
Response.Redirectis used the expectation is to send only the 302 header to the client. Hence by default, it flushes the response & aborts the current thread, so the subsequent action will not be performed.Example, in the authorization / authentication module once we know that the user is not eligible to access the resource, we just do a redirection and rest of the event life cycle should not get executed for security reasons.