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");
?
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");
?
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.