I'm using Response.Redirect(url, **false**);
in order to prevent an exception. However, I have seen it recommended to use CompleteRequest();
after it, and I don't understand that. Example: here on MSDN . As far as I know, CompleteRequest
will not terminate the execution (though it will affect rendering) so any code with persisting consequences such as database writes - will have an effect. And therefore stopping the code must be managed by a return
etc. And it is not needed for the Redirect
to process.
Is my understanding correct? (I'm asking because of the link above and similar ones.)
Your understanding is correct. Using
CompleteRequest()
signals the ASP.NET runtime that no further processing on the request is needed and it bypasses all the events in the HTTP pipeline and directly calls theEndRequest
event. However, it won't stop executing the the remaining lines of code. It would just end the request gracefully in order to prevent data loss.