Jose Gregorio
Jose Gregorio

Reputation: 59

Forms Authentication Cookie MVC 3 and MVC 2

im kind of new on mvc 3 and i just spot this on a sample project in 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));

and this on a mvc 3 sample project

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

My question is does this have the same effect ?? how do i specify the live of the cookie on mvc 3 ??

Thx in advance

Upvotes: 0

Views: 575

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038890

My question is does this have the same effect ??

No, the two code fragments are not equivalent because in the first you are manually setting the timeout validity of the ticket to 10 minutes whereas in the second it uses the Timeout property in your web.config:

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

It would have had the same effect if you set the timeout in web.config to 10 minutes.

Upvotes: 2

Related Questions