Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to another any episerver page from MVC controller?

How to redirect to any page (eg Home) from any MVC controller in Episerver? eg after login - redirect to the start page.

like image 361
AndrewVA Avatar asked Mar 11 '14 13:03

AndrewVA


2 Answers

To redirect to any MVC action:

public ActionResult Index()
{
    return RedirectToAction("Index", "Home");
}

Redirect to the configured start page of the site:

public ActionResult Index()
{
    PageData startPage =
        ServiceLocator.Current.GetInstance<IContentRepository>().Get<PageData>(ContentReference.StartPage);

    // get URL of the start page
    string startPageUrl = ServiceLocator.Current.GetInstance<UrlResolver>()
                .GetVirtualPath(startPage.ContentLink, startPage.LanguageBranch);

    return Redirect(startPageUrl);
}
like image 169
Thomas Krantz Avatar answered Oct 03 '22 00:10

Thomas Krantz


You can actually still use the RedirectToAction with EPiServer, as long as you also supply the content reference of the page.

public ActionResult Index()
{
    return RedirectToAction("ActionName", new { node = ContentReference.StartPage });
}

This has been tested in EPiServer 7.5.440.0.

like image 40
aolde Avatar answered Oct 02 '22 22:10

aolde