forms authentication question

Discussion in 'ASP .Net' started by bill yeager, Jul 24, 2003.

  1. bill yeager

    bill yeager Guest

    Everything is working in my authentication process except
    for the fact that I can't retrieve the "UserData" property
    from the "FormsAuthenticationTicket".

    Write before I do a "RedirectFromLoginPage", I check
    the "UserData" property of
    the "FormsAuthenticationTicket". It's set to the
    value "Admin" (a role for the user) which is what I want.

    Here is the code:

    strUserName = CType(drOLEDBNicemScheduling.GetValue(1) &
    Chr(32) & drOLEDBNicemScheduling.GetValue(2), String)
    'Set the authentication ticket
    Dim arrRoles(0) As String
    arrRoles(0) =
    drOLEDBNicemScheduling.GetValue(3)
    Dim ticket As New
    FormsAuthenticationTicket(1, strUserName, Now, DateAdd
    (DateInterval.Minute, 60, Now),
    ValidateLogin.PersistantCookie, arrRoles(0))
    Dim cookie = New HttpCookie
    (FormsAuthentication.FormsCookieName,
    FormsAuthentication.Encrypt(ticket))
    If ValidateLogin.PersistantCookie Then
    Response.Cookies.Add(cookie)
    End If
    'Create Identity
    Dim objIdentity As New
    Security.Principal.GenericIdentity(strUserName)
    Dim objPrincipal As New
    Security.Principal.GenericPrincipal(objIdentity, arrRoles)

    FormsAuthentication.RedirectFromLoginPage(strUserName,
    ValidateLogin.PersistantCookie)

    However, once I get in the Global.asax file in
    the "Application_AuthenticateRequest" event (fired by the
    FormsAuthentication.RedirectFromLoginPage method), I check
    the "UserData" property of the ticket and it's an empty
    string! All the other properties pertaining to the ticket
    are there. I'm setting up the cookie, so the "Userdata"
    property should be populated.

    Here is the code in the global.asax file:

    Sub Application_AuthenticateRequest(ByVal sender As
    Object, ByVal e As EventArgs)

    If (Not (HttpContext.Current.User Is Nothing)) Then
    If
    HttpContext.Current.User.Identity.AuthenticationType
    = "Forms" Then
    If
    HttpContext.Current.User.Identity.IsAuthenticated Then
    Dim id As FormsIdentity =
    HttpContext.Current.User.Identity
    Dim ticket As
    FormsAuthenticationTicket = id.Ticket
    Dim roles(0) As String
    roles(0) = ticket.UserData
    HttpContext.Current.User = New
    System.Security.Principal.GenericPrincipal(id, roles)
    End If
    End If
    End If

    End Sub

    What am I doing wrong??? I need to be able to identify the
    role of the user (they will only have 1 role).

    Thanks,

    Bill........
     
    bill yeager, Jul 24, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Connell
    Replies:
    1
    Views:
    568
    Natty Gur
    Oct 21, 2003
  2. Eric
    Replies:
    2
    Views:
    1,564
    Tommy
    Feb 13, 2004
  3. JEFF
    Replies:
    1
    Views:
    1,055
    =?Utf-8?B?YnJpYW5zW01DU0Rd?=
    Nov 12, 2007
  4. Keltex
    Replies:
    1
    Views:
    453
    Dominick Baier [DevelopMentor]
    Jan 24, 2006
  5. Eric
    Replies:
    2
    Views:
    644
Loading...

Share This Page