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

31,895

if you don't want to use RedirectToAction (for me is the right choice) you can use

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

UPDATE

As stated in the comments, this should also works

return Redirect("~/");
Share:
31,895
Admin
Author by

Admin

Updated on August 20, 2020

Comments

  • Admin
    Admin over 3 years

    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?

  • AKS
    AKS over 8 years
    Thanks you , your solution save a day of mine.
  • Curtis Yallop
    Curtis Yallop over 8 years
    Url.Content should not be required. You can just do: return Redirect("~");
  • ᴍᴀᴛᴛ ʙᴀᴋᴇʀ
    ᴍᴀᴛᴛ ʙᴀᴋᴇʀ about 8 years
    Perfect solution! Works great when using MVC Areas too unlike trying to use RedirectToAction("Default");
  • tomfanning
    tomfanning over 6 years
    @CurtisYallop I had to do return Redirect("~/");