Issue with authentication

Last post 05-16-2008 8:01 AM by mpaterson. 2 replies.

Sort Posts:

  • Issue with authentication

    05-14-2008, 4:44 PM
    • Loading...
    • mpaterson
    • Joined on 11-26-2006, 10:24 PM
    • St. Petersburg, Florida
    • Posts 964

    I am working on a site with a custom db (ie. not aspnetdb) and am just creating a quick work around for login functionality.
    Everything seems to be working ok accept the value of the cookie is always null during Application_AuthenticateRequest

     And here is the AuthenticateRequest functionality: 

    Dim app As HttpApplication = CType(sender, HttpApplication)
            Dim cookie As HttpCookie = Response.Cookies(FormsAuthentication.FormsCookieName)
    
            If (cookie IsNot Nothing) Then
                Dim encryptedTicket As String = cookie.Value
                If (encryptedTicket IsNot Nothing) Then
                    If (encryptedTicket.Length > 0) Then
                        Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(encryptedTicket)
                        Dim roles As String() = ticket.UserData.Split(New Char() {","})
                        Dim identity As FormsIdentity = New FormsIdentity(ticket)
                        Dim user As System.Security.Principal.GenericPrincipal = New System.Security.Principal.GenericPrincipal(identity, roles)
                    End If
                    
                End If
            End If

     And here is the login functionality
    Dim roles As String = "Admin"
                Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, Login1.UserName, DateTime.Now, DateTime.Now.AddMinutes(40), False, roles)
                Dim encryptedTicket As String = FormsAuthentication.Encrypt(ticket)
                Dim cookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName)
                cookie.Value = encryptedTicket
    
    
                If (Response.Cookies(FormsAuthentication.FormsCookieName) IsNot Nothing) Then
                    Response.Cookies.Remove((Response.Cookies(FormsAuthentication.FormsCookieName).Name))
                End If
    
                Response.Cookies.Add(cookie)
    
                Response.Redirect(FormsAuthentication.GetRedirectUrl(Login1.UserName, True), True)

     

     

    Any ideas?

    If everything happens for a reason what is the reason for this error?
  • Re: Issue with authentication

    05-16-2008, 2:39 AM
    Answer

    mpaterson:

    Dim cookie As HttpCookie = Response.Cookies(FormsAuthentication.FormsCookieName)

    Hi

    Not sure where you get this example, but I suggest you use the same way as said in this KB to set user context from page.

    http://support.microsoft.com/kb/311495/en-us

    Hope it helps.

    Best Regards
    XiaoYong Dai
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Issue with authentication

    05-16-2008, 8:01 AM
    • Loading...
    • mpaterson
    • Joined on 11-26-2006, 10:24 PM
    • St. Petersburg, Florida
    • Posts 964

    Yeah that is the approach I ended up taking.

    Thanks

    If everything happens for a reason what is the reason for this error?
Page 1 of 1 (3 items)