开发者

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

When I redirect like this way

 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 开发者_JS百科{
      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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜