How to redirect to any page (eg Home) from any MVC controller in Episerver? eg after login - redirect to the start page.
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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With