Benny Ng
2005-09-19 05:55:08 PM
This is a multi-part message in MIME format.
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.3790.2491" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=1>The method of following can generated the cookie
for login:</FONT></DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1>//isPersistent is true;</FONT></DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial
size=1>FormsAuthentication.SetAuthCookie(Session["UserName"].ToString()
,isPersistent) ;</FONT></DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=1>But the second way that of following can't be
generated the cookie:</FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=1></FONT> </DIV>
<DIV><FONT size=1>string userRoles = "Administrator";</FONT></DIV>
<DIV><FONT size=1>FormsAuthenticationTicket Ticket = new
FormsAuthenticationTicket
(<BR> 1,<BR> Session["UserName"].ToString()
,<BR> DateTime.Now,<BR> DateTime.Now.AddMinutes(30),
<BR> isPersistent,<BR> userRoles,<BR> "/")
; //Create authentication ticket<BR>string HashTicket =
FormsAuthentication.Encrypt (Ticket) ; //Encrypt the Ticket string</FONT></DIV>
<DIV><FONT size=1>HttpCookie UserCookie = new
HttpCookie(FormsAuthentication.FormsCookieName, HashTicket) ; <BR>//Generate
Cookie<BR>Context.Response.Cookies.Add (UserCookie) ; //Export
Cookie</FONT></FONT></DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1>------------------------------------</FONT></DIV>
<DIV><FONT face=Arial size=1>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)</FONT></DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1>Any suggestion are appreciated.
Thanks!</FONT></DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1></FONT> </DIV>
<DIV><FONT face=Arial size=1>Benny Ng</FONT></DIV></BODY></HTML>