asp.net-mvc 如何将我的操作重定向到网站的根目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10291966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I redirect my action to the root of the web site?
提问by Iridio
I have the following code in my controller to redirect my user after he has logged out:
我的控制器中有以下代码可以在用户注销后重定向:
public ActionResult Logout()
{
FormsAuthentication.SignOut();
return new RedirectToRouteResult(
new RouteValueDictionary(
new {
area = "Administration",
controller = "Menus",
action = "Home"
}
)
);
}
I would like to redirect the user to / or the base URL (root) of my site. Is there a way that I can do this without having to give details of the area, controller and action?
我想将用户重定向到 / 或我网站的基本 URL(根)。有没有一种方法可以做到这一点,而无需提供区域、控制器和操作的详细信息?
回答by Iridio
if you don't want to use RedirectToAction(for me is the right choice)
you can use
如果你不想使用RedirectToAction(对我来说是正确的选择)你可以使用
return Redirect(Url.Content("~/"));
UPDATE
更新
As stated in the comments, this should also works
正如评论中所述,这也应该有效
return Redirect("~/");

