05 April 2017

In Response.Redirect("URL"), Should We Use True or False?

Response.Redirect("URL", true);
Response.Redirect("URL", false);

Did you know that using true or false is just a matter of how you control the logic flow of your code? We use true to abort the thread so that nothing will execute once you redirect the page. Then, we use false when you don't want to abort the thread after the Response.Redirect executes.

For some developers, using true is considered a bad practice because it's a sign that you have no control on your code's logic and you're simply aborting the thread and the application will not continue when an error arises.

But the funny thing is that I've seen a lot of developers not putting either true or false whenever they use Response.Redirect and keep saying that using true is not a good practice. But the truth is that when you don't declare a false value, "true" is the default when you use Response.Redirect.

No comments:

Post a Comment