Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if currently logged in user has persistent authcookie

I need to edit userdata in an a FormsAuthentication AuthCookie of the currently logged in user. I don't see how to find out if the current user has chosen a persistent cookie ("Remember Me").

//user is already logged in...

HttpCookie authCookie = FormsAuthentication.GetAuthCookie(username, ispersistant); //how to I determine 'ispersistant'?

FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);

FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, NEWuserdata);

authCookie.Value = FormsAuthentication.Encrypt(newTicket);

HttpContext.Current.Response.SetCookie(authCookie);

Anybody got any ideas? Thanks

like image 353
Greg Avatar asked Oct 29 '11 09:10

Greg


1 Answers

The FormsAuthentication.GetAuthCookie method only creates a new cookie. It does not get you the earlier made cookie.

On your login page you probably have something like this:

FormsAuthentication.GetAuthCookie (userID, chkPersistCookie.Checked)

And to know when the user is authenticated you can do

this.Context.User.Identity.IsAuthenticated

I actually don't know for sure if you can deduce the fact that the user has a persistent auth cookie. One thing is checking the cookie for a expiry date.

In this question there is a example for reading the authentication cookie.

like image 103
Martijn B Avatar answered Oct 12 '22 23:10

Martijn B