简体   繁体   English

如何将我的操作重定向到网站的根目录?

[英]How can I redirect my action to the root of the web site?

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. 我想将用户重定向到我网站的基本URL(根)。 Is there a way that I can do this without having to give details of the area, controller and action? 有没有办法我可以做到这一点,而不必提供区域,控制器和行动的细节?

if you don't want to use RedirectToAction (for me is the right choice) you can use 如果您不想使用RedirectToAction (对我来说是正确的选择),您可以使用

return Redirect(Url.Content("~/"));

UPDATE UPDATE

As stated in the comments, this should also works 如评论中所述,这也应该有效

return Redirect("~/");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何重定向到MVC网站我的父母行动? - How do I redirect to my parent action in MVC site? 如何从ASP.NET MVC中的同一操作重定向到另一个视图或外部站点? - How can I redirect to either another view or an external site from the same action in ASP.NET MVC? 我如何将Outlook Web App嵌入我的网站? - How i can embed Outlook Web App into my site? 如何从MVC4中的异步动作重定向到另一个动作 - How can I redirect to another action from my Asynchronous Action in MVC4 如何使用 Bearer 令牌在 Z2567A5EC9705EB7AC2C984033E 站点中授权我的 web api controller? - How can I authorize my web api controller in my web site with Bearer token? 如何从Web Forms Site.Master页面重定向到MVC页面? - How can I Redirect to an MVC page from a Web Forms Site.Master page? 本地化网站的ASP.NET MVC 3.0根重定向 - ASP.NET MVC 3.0 Root Redirect for Localized Web Site 转到网站根目录时,Web.config重定向到页面 - Web.config redirect to page when going to site root 如何在ASP.NET MVC3网站上对我的Json结果进行单元测试? - How can I unit test my Json result in an ASP.NET MVC3 web site? 如何将android编辑文本中的值发送到我的网站进行登录? - How can i send values from android edit text to my web site for login?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM