【发布时间】:2011-01-30 17:05:08
【问题描述】:
当我在开发 Asp.Net MVC 3 应用程序时,我在我的应用程序中使用了FormAuthentication。
问题是,在登录系统后,当我关闭浏览器(没有注销)并再次在浏览器中打开页面(比如说/Admin/ProductList/)时,page is still being invoked 和I got focus in my controller too。 [这真的很糟糕! :( ]
我想要的是,当我关闭浏览器并再次返回任何页面时,它应该转到logged in page。
请查看给定的代码以便您理解。
public void SignIn(string userName, bool isCookiePersistent)
{
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddDays(14),
createPersistentCookie, string.Empty);
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(userName, isCookiePersistent);
if (authTicket.IsPersistent)
{
authCookie.Expires = authTicket.Expiration;
}
authCookie.Value = FormsAuthentication.Encrypt(authTicket);
HttpContext.Current.Response.Cookies.Add(authCookie);
}
public void SignOut()
{
FormsAuthentication.SignOut();
}
Web.Config 代码:
<authentication mode="Forms">
<forms loginUrl="~/Admin/Login" timeout="2880" />
</authentication>
My page is getting in **Redirection Loop**: This is the main issue.
我错过了any other settings or global.asax event handling吗?
请给我任何解决方案来帮助我。
提前致谢。
【问题讨论】:
标签: asp.net asp.net-mvc session asp.net-mvc-3