Is there a simple way to redirect the entire page (not just the partial view) to the login page after the session has expired?
I have tried the following solutions, but can't get it to work:
- .Net MVC Partial View load login page when session expires
- How to redirect full page rather then only partial view changing?
My problem is that the partial view redirects to the Login-page, and not the entire page (same problem as in the links).
Controller
[HttpPost]
public PartialViewResult LogPartialView(string a, int? b, string c, string d, int? e, string f)
{
//If the user is "Admin" -> display Logs for all customers.
if (Roles.IsUserInRole(WebSecurity.CurrentUserName, "Admin"))
{
if (Session["myID"] == null)
{
ExpireSession();
}
//Some code
return PartialView("LogPartialLayout", model);
}
I wanted to return Redirect ("~/") if myID is null but it doesnt work since it expects a Partial View.
Error-message: Cannot implicitly convert type 'System.Web.Mvc.RedirectResult' to 'System.Web.Mvc.PartialViewResult'
public void ExpireSession()
{
Session.Abandon();
WebSecurity.Logout();
Response.Redirect("~/");
}
