T
Tony
Can anybody tells if I'm doing something wrong in this code
and why the user authentication ticket always expires 30
minutes later, even though I set the cookie expiration
date to the maximum value, and if I'm reading the cookie
back the right way ?
Dim myTicket As New FormsAuthenticationTicket(1, _
myUser_, _
DateTime.Now, _
DateTime.Now.AddMinutes(30), _
myCheckbox.Checked, _
myUserData, _
FormsAuthentication.FormsCookiePath)
Dim hash As String = FormsAuthentication.Encrypt(myTicket)
Dim myCookie As HttpCookie
=New HttpCookie(FormsAuthentication.FormsCookieName, hash)
If (myTicket.IsPersistent) Then myCookie.Expires=
DateTime.MaxValue
Response.Cookies.Add(myCookie)
Dim url As String = FormsAuthentication.GetRedirectUrl
(myUser, true)
Response.Redirect(url)
'THEN I READ THE COOKIE IN THE Global.asax FILE:
If (Not (HttpContext.Current.User Is Nothing)) Then
If (HttpContext.Current.User.Identity.IsAuthenticated) Then
If (HttpContext.Current.User.Identity.AuthenticationType
= "Forms") Then
Dim myID As System.Web.Security.FormsIdentity =
HttpContext.Current.User.Identity
Dim myTicket As
System.Web.Security.FormsAuthenticationTicket = myID.Ticket
Dim userData As String = myTicket.UserData
Dim myRoles As String() = Split (userData, ",")
HttpContext.Current.User = New
System.Security.Principal.GenericPrincipal(myID, myRoles)
End If
End If
End If
and why the user authentication ticket always expires 30
minutes later, even though I set the cookie expiration
date to the maximum value, and if I'm reading the cookie
back the right way ?
Dim myTicket As New FormsAuthenticationTicket(1, _
myUser_, _
DateTime.Now, _
DateTime.Now.AddMinutes(30), _
myCheckbox.Checked, _
myUserData, _
FormsAuthentication.FormsCookiePath)
Dim hash As String = FormsAuthentication.Encrypt(myTicket)
Dim myCookie As HttpCookie
=New HttpCookie(FormsAuthentication.FormsCookieName, hash)
If (myTicket.IsPersistent) Then myCookie.Expires=
DateTime.MaxValue
Response.Cookies.Add(myCookie)
Dim url As String = FormsAuthentication.GetRedirectUrl
(myUser, true)
Response.Redirect(url)
'THEN I READ THE COOKIE IN THE Global.asax FILE:
If (Not (HttpContext.Current.User Is Nothing)) Then
If (HttpContext.Current.User.Identity.IsAuthenticated) Then
If (HttpContext.Current.User.Identity.AuthenticationType
= "Forms") Then
Dim myID As System.Web.Security.FormsIdentity =
HttpContext.Current.User.Identity
Dim myTicket As
System.Web.Security.FormsAuthenticationTicket = myID.Ticket
Dim userData As String = myTicket.UserData
Dim myRoles As String() = Split (userData, ",")
HttpContext.Current.User = New
System.Security.Principal.GenericPrincipal(myID, myRoles)
End If
End If
End If