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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top