What is difference between Response.Redirect("http://url") and Response.Write("REDIRECT=http://url")?

I'm working on ASP.NET MVC3 with C#.

What is difference between Response.Redirect("http://www.google.com"); and Response.Write("REDIRECT=http://www.google.com");?

Answers


The difference is that the first will replace the response with a redirection page and end the execution, while the second will just write the text to the response stream and continue with creating the rest of the page.


Response.Redirect() sets an HTTP 302 header along with the URL to be redirected to.

Response.Write("REDIRECT=http://www.google.com"); will write that string to the response body, as in that redirect text would be appended to the HTML of your web page.


This will create the correct full HTTP Header for you:

Response.Redirect("http://www.google.com");

You have the ability to set or change some paramters for the HTTP Header.

HttpResponse Class

e.g set HTTP Status Code 404 or 500 or in your case 302 for redirect.

e.g set the HTTP Mime-type for jpg

Will write into the Body in your response..like a string output

Response.Write("REDIRECT=http://www.google.com");

The methods in question are quite self explanatory :)

Response.Redirect("http://www.google.com");

The Redirect will redirect you to another page, in the case it will take you to Google's home page.

Response.Write("REDIRECT=http://www.google.com");

The Write method will write a string of text to the web page. In this case it will write the text "REDIRECT=http://www.google.com" to your web page.

Play around with these 2 methods in your web project and see what happens.


Need Your Help

facebook api date conversion

php codeigniter facebook-graph-api

I am making my first app in codeigniter that draws birthdays from the facebook api and places them into a mysql database. The dates coming from the facebook api are 00-00-0000 and I need them to be

Reverse animation for Google Map marker removal?

javascript google-maps google-maps-api-3 google-maps-markers

I know I can animate the "adding" of a marker on a google map, a la https://developers.google.com/maps/documentation/javascript/overlays#MarkerAnimations