我有一个网站,如预期的工作在我的开发框。也就是说,表单认证票在30天后到期。这是通过以下代码实现的
string roles = UserManager.getAuthenticationRoleString(txtUsername.Text);
HttpCookie formscookie = FormsAuthentication.GetAuthCookie(txtUsername.Text, true);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(formscookie.Value);
FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(1, ticket.Name, DateTime.Now, DateTime.Now.AddDays(30), true, roles, ticket.CookiePath);
HttpCookie newCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(newticket));
newCookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(newCookie);我用小提琴来检查是否正确设置了有效期,我得到了以下信息
.ASPXAUTH=84AB5430CF4B1C5F9B59C9285288B41F156FCAFA2A169EACE17A7778A392FA69F66770FD8A08FFD06064B00F0BD788FEEC4A5894B7089239D6288027170A642B3B7EB7DB4806F2EBBCF2A82EE20FD944A38D2FE253B9D3FD7EFA178307464AAB4BCB35181CD82F6697D5267DB3B62BAD; expires=Thu, 21-Jan-2010 18:33:20 GMT; path=/; HttpOnly因此,我预计它将在30 days...But到期,它只会使它大约30分钟。
我还有3条关于我的环境/代码的有趣的消息。
生产框中的
的角色检查。
-
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
// Get the stored user-data, in this case, our roles
string userData = ticket.UserData;
string[] roles = userData.Split('|');
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id, roles);
}
}
}
}发布于 2011-02-01 18:27:47
您需要向web.config文件中添加一个机器键标记。它正在再生,这会导致你过早的超时。
这与以下问题类似:
发布于 2009-12-22 20:59:55
如果问题是生产框上的用户被踢了,必须再次通过FormsAuthentication登录,那么问题可能是与IIS相关的,而不是.NET。
我以前遇到过一些问题,在应用程序中,世界上所有的超时设置都没有什么区别,用户被引导得太早了。
检查网站和应用程序池的IIS设置。在与超时有关的两种设置中都有设置。
如果II6:
网站属性下的
。
要调试,您可以禁用池上的所有健康和性能检查,但是要非常小心,因为如果应用程序失控,这可能会影响服务器。
您还可以尝试在web.config中放置超时设置:
<system.web>
<authentication mode="Forms">
<forms timeout="XXXXX"/>
</authentication>
</system.web>总之,只是一些想法,从个人经验,类似的问题。希望能帮上忙!
https://stackoverflow.com/questions/1948375
复制相似问题