Cannot retrieve UserData in Forms Authentication

From: John Kievlan (jodakim_at_comcast.com)
Date: 07/24/03


Date: Thu, 24 Jul 2003 14:33:41 -0700


I am using FormsAuthentication for my application, and in
the UserData property of the FormsAuthenticationTicket
I'm storing the roles that the user is a member of, to
retrieve in global.asax and create a GenericPrincipal
object. Problem is, after the user logs in, I can get
the ticket just fine from the cookie, and all the data is
there -- except for the UserData property. It's empty.

I set the UserData as follows:

Dim authTicket As New FormsAuthenticationTicket(1,
txtUserID.Text, DateTime.Now, DateTime.Now.AddHours(1),
False, GetRoles(txtUserID.Text))
Dim encryptedTicket As String =
FormsAuthentication.Encrypt(authTicket)
Dim authCookie As New HttpCookie
(FormsAuthentication.FormsCookieName, encryptedTicket)
Response.Cookies.Add(authCookie)

Then I get the same cookie back in global.asax:

Dim cookieName As String =
FormsAuthentication.FormsCookieName
Dim authCookie As HttpCookie = Context.Request.Cookies
(cookieName)

If authCookie Is Nothing Then Exit Sub

Dim authTicket As FormsAuthenticationTicket =
FormsAuthentication.Decrypt(authCookie.Value)

If authTicket Is Nothing Then Exit Sub

Dim roles() As String = Split
(authTicket.UserData, "|") ' Roles are in the
format "Role1|Role2|...|RoleN"

Dim id As New FormsIdentity(authTicket)

Dim principal As New GenericPrincipal(id, roles)

Context.User = principal

And the user isn't in the given roles. I went back and
put:

Response.Write("'" & authTicket.UserData & "'")

in the global.asax file, and I get an empty string.
Anyone have an idea?



Relevant Pages

  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcsd)