我有一个会话过期属性
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var context = filterContext.HttpContext;
if (context.Session != null)
{
if (context.Session.IsNewSession)
{
string sessionCookie = context.Request.Headers["Cookie"];
if ((sessionCookie == null) && (sessionCookie.IndexOf("ASP.NET_SessionId") < 0))
{
FormsAuthentication.SignOut();
filterContext.Result = new RedirectResult("~/Login/Index");
}
}
}
base.OnActionExecuting(filterContext);
}
和我的控制器
public ActionResult Index(Login login)
{
//WebSecurity.Login
User user = new User();
string encodePassword = Crytography.EncodePasswordToBase64(login.Password);
var consumer = user.Get(u => u.f_username == login.Username && u.f_password == encodePassword).SingleOrDefault();
if (consumer != null)
{
FormsAuthentication.SetAuthCookie(login.Username, false);
var expiration = 3;
var authTicket = new FormsAuthenticationTicket(1, login.Username, DateTime.Now, DateTime.Now.AddSeconds(expiration), false, "Admin");
var encryptedTicket = FormsAuthentication.Encrypt(authTicket);
var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
HttpContext.Response.Cookies.Add(authCookie);
return RedirectToAction("Index", "Main");
}
return View();
我的问题是当重定向主页的导航时仍然存在。