Why I can't generate the cookie by Forms Authentication?

B

Benny Ng

The method of following can generated the cookie for login:

//isPersistent is true;

FormsAuthentication.SetAuthCookie(Session["UserName"].ToString() ,isPersistent) ;





But the second way that of following can't be generated the cookie:

string userRoles = "Administrator";
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket (
1,
Session["UserName"].ToString() ,
DateTime.Now,
DateTime.Now.AddMinutes(30),
isPersistent,
userRoles,
"/") ; //Create authentication ticket
string HashTicket = FormsAuthentication.Encrypt (Ticket) ; //Encrypt the Ticket string
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket) ;
//Generate Cookie
Context.Response.Cookies.Add (UserCookie) ; //Export Cookie



------------------------------------
And is that two ways of the above can be same to generate the cookie for my login?(if the second one is right to generated cookie)

Any suggestion are appreciated. Thanks!


Benny Ng
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top