2012-01-30 63 views
0

对MVC 3 IM一种新的,我只是发现这个实例项目中的MVC 2窗体身份验证Cookie MVC 3和MVC 2

FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,Username,DateTime.Now,DateTime.Now.AddMinutes(10), RememberMe, Username); 
string encTicket = FormsAuthentication.Encrypt(authTicket); 
this.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); 

,这对MVC 3示例项目

FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); 

我的问题是这是否具有相同的效果?我如何指定在mvc 3上的cookie的实况?

THX提前

回答

2

我的问题是,这是否有同样的效果?

没有,两个代码片段是不等价的,因为在第一手动设置门票的超时有效期为10分钟,而在第二个它使用在你的web.config超时属性:

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/LogOn" timeout="2880" /> 
</authentication> 

如果将web.config中的超时设置为10分钟,它会产生相同的效果。

+0

thx很多@Daring – 2012-01-30 17:00:42