Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the alternative to Response.Redirect() asp.net?

Hi One of the tips in "website performance tips" in various blogs says "Avoid Redirects". In my case, I am using Response.Redirect for the same page. I am passing a querystring and displaying appropriate information to the user.

Response.Redirect("FinalPage.aspx?NextID=" + ID);

So in our business logic, i am reloading the same page with different information.

So how do i avoid redirect? Is there any other alternative? BTW, my aim is to gain some performance there.

like image 796
User13839404 Avatar asked Feb 04 '11 16:02

User13839404


1 Answers

Redirect is the R in the PRG pattern which is an accepted pattern for processing posted requests. So it is definitely not evil.

However, there used to be a common interview question: "What is the difference between Server.Redirect() and Server.Transfer() and which one must be used?". People used to say Transfer because it did not involve a round-trip but web has changed so much since then. In those days you could not re-use the the common logic in the views unless you use Transfer or Redirect, but nowadays especially with ASP NET MVC there are tons of a ways to do that.

In your case, I am all for PRG and I believe redirect is semantically more correct. Also it prevents the form being re-submited if user clicks F5 or refresh.

like image 76
Aliostad Avatar answered Nov 15 '22 05:11

Aliostad