Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is the difference between Response.Redirect vs new RedirectResult()?

When I redirect like this way

 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
      filterContext.Result = new RedirectResult("https://mydom.com");
 }

so the browser redirects to http://mydom.com/httpS://mydom.com

but if I redirect this way

 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
      var res = filterContext.HttpContext.Response;
      filterContext.Result = res.Redirect("https://mydom.com");
 }

so the browser redirect correctly to https://mydom.com

Why there is the difference?

like image 861
theateist Avatar asked Aug 11 '11 11:08

theateist


People also ask

What is the difference between response redirect () and Server transfer ()?

Response. Redirect simply sends a message (HTTP 302) down to the browser. Server. Transfer happens without the browser knowing anything, the browser request a page, but the server returns the content of another.

Which one is better response redirect VS Server transfer?

The Response. Redirect method redirects a request to a new URL and specifies the new URL while the Server. Transfer method for the current request, terminates execution of the current page and starts execution of a new page using the specified URL path of the page. Both Response.

What is the difference between return view and return redirect?

Return View doesn't make a new requests, it just renders the view without changing URLs in the browser's address bar. Return RedirectToAction makes a new request and the URL in the browser's address bar is updated with the generated URL by MVC.

What can I use instead of a response redirect?

For instance, instead of a "form" button that causes a postback and redirect, you could use a LinkButton that will behave like a hyperlink, allowing the browser to request the new page directly.


1 Answers

First of all, RedirectResult is a class whereas HttpResponse.Redirect is a method. While the former redirects the user to a specified URI the latter will redirect you to a given URL. To see the differences between URL and URI see here.

Hope that helps

like image 143
Shaokan Avatar answered Nov 16 '22 06:11

Shaokan