theateist
theateist

Reputation: 14399

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?

Upvotes: 6

Views: 3721

Answers (1)

Shaokan
Shaokan

Reputation: 7684

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

Upvotes: 3

Related Questions