2014-09-29 27 views
-1

任何人都可以告诉我有关ASP.NET MVC 5中的不同重定向方法吗?我有用户Redirect,RedirectToAction,RedirectPermanent,但我想知道在哪种情况下使用哪一个。ASP.NET MVC中有哪些不同的重定向方法?

请描述ASP.NET MVC 5中除此之外的所有可用的重定向方法。

+0

可能的重复[Wh at是在ASP.NET MVC的Redirect和RedirectToAction之间的区别?](http://stackoverflow.com/questions/12198909/what-is-the-difference-between-redirect-and-redirecttoaction-in-asp-net- mvc) – 2014-09-29 11:59:41

+0

我想知道除这些之外的其他重定向技术。 – 2014-09-29 12:04:56

回答

1
  • 重定向 - Redicect到指定的URL(HTTP 302)
  • RedirectPernament - 同Redicect但与HTTP 301响应
  • RedirectToAction - 重定向到动作(HTTP 302)
  • RedirectToActionPernament - 同RedirectToAction但与HTTP 301响应
  • RedirectToRoute - Redicect到路线(HTTP 302)
  • RedirectToRoutePernament - 同RedirectToRoute但与HTTP 301响应

所有内部重定向都执行相同的操作(HTTP 302或HTTP 301)。方法不同,他们是如何解决URL重定向:

  • 重定向使用URL作为参数传递
  • RedirectToAction从操作名称或操作名称和控制器的名称生成URL
  • RedirectToRoute从路由名称生成URL
0

您可以使用如下响应重定向:

Response.Redirect("yoururl");//you can use route like: Response.Redirect("~/Home/About");