The Redirect() creates a result, that is handled in MVC, and based on it, it actually calls the other method, Response.Redirect(), internally.
The difference between the two, are that the result from the Redirect() call, is handled by MVC, and the Response.Redirect() is handled by ASP.Net.
Inside a controller, you should return the result from Redirect. Response.Redirect will just add headers to the Response, allowing you to set a redirect, then execute more code before returning the result.
If you call Response.Redirect inside a controller, and then return another result, you could end up redirecting to the url, when you actually wanted to return some content instead.
Redirect() vs Response.Redirect()
What is the difference between
And
Thanks in advance!
Hi,
I guess you are taking about https://docs.microsoft.com/en-us/dotnet/api/system.web.httpresponse.redirect?view=netframework-4.8 and https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.controller.redirect?view=aspnet-mvc-5.2
The Redirect() creates a result, that is handled in MVC, and based on it, it actually calls the other method, Response.Redirect(), internally.
The difference between the two, are that the result from the Redirect() call, is handled by MVC, and the Response.Redirect() is handled by ASP.Net.
Inside a controller, you should return the result from Redirect. Response.Redirect will just add headers to the Response, allowing you to set a redirect, then execute more code before returning the result.
If you call Response.Redirect inside a controller, and then return another result, you could end up redirecting to the url, when you actually wanted to return some content instead.
HTH :)
is working on a reply...