forms authentication question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bill yeager

    #1

    forms authentication question

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

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

    Here is the code:

    strUserName = CType(drOLEDBNi cemScheduling.G etValue(1) &
    Chr(32) & drOLEDBNicemSch eduling.GetValu e(2), String)
    'Set the authentication ticket
    Dim arrRoles(0) As String
    arrRoles(0) =
    drOLEDBNicemSch eduling.GetValu e(3)
    Dim ticket As New
    FormsAuthentica tionTicket(1, strUserName, Now, DateAdd
    (DateInterval.M inute, 60, Now),
    ValidateLogin.P ersistantCookie , arrRoles(0))
    Dim cookie = New HttpCookie
    (FormsAuthentic ation.FormsCook ieName,
    FormsAuthentica tion.Encrypt(ti cket))
    If ValidateLogin.P ersistantCookie Then
    Response.Cookie s.Add(cookie)
    End If
    'Create Identity
    Dim objIdentity As New
    Security.Princi pal.GenericIden tity(strUserNam e)
    Dim objPrincipal As New
    Security.Princi pal.GenericPrin cipal(objIdenti ty, arrRoles)

    FormsAuthentica tion.RedirectFr omLoginPage(str UserName,
    ValidateLogin.P ersistantCookie )

    However, once I get in the Global.asax file in
    the "Application_Au thenticateReque st" event (fired by the
    FormsAuthentica tion.RedirectFr omLoginPage 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_Aut henticateReques t(ByVal sender As
    Object, ByVal e As EventArgs)

    If (Not (HttpContext.Cu rrent.User Is Nothing)) Then
    If
    HttpContext.Cur rent.User.Ident ity.Authenticat ionType
    = "Forms" Then
    If
    HttpContext.Cur rent.User.Ident ity.IsAuthentic ated Then
    Dim id As FormsIdentity =
    HttpContext.Cur rent.User.Ident ity
    Dim ticket As
    FormsAuthentica tionTicket = id.Ticket
    Dim roles(0) As String
    roles(0) = ticket.UserData
    HttpContext.Cur rent.User = New
    System.Security .Principal.Gene ricPrincipal(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........
Working...