windows authentication with forms

From: dennisG (dennis79_at_pandora.be)
Date: 08/23/05


Date: 23 Aug 2005 03:01:46 -0700

Hi,

I have a problem with windows authentication, with a web based form. I
can logon with the function logonuser with my username, password and
domain, but I don't get the windows rights of my windows account. I've
looked to different websites, but it doesn't solved my problem.

My code, function that works on the login button
        Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles cmdLogin.Click
            Dim username As String = txtUsername.Text
            Dim password As String = txtPassword.Text
            Dim domain As String = "Domainname"

            If ValidateLogin(username, password, domain) = True Then
                FormsAuthentication.RedirectFromLoginPage(username,
chkRemember.Checked)
            Else
                lblError.Visible = True
            End If
        End Sub

And validation function:
        Private Function ValidateLogin( _
                    ByVal Username As String, _
                    ByVal Password As String, _
                    ByVal Domain As String) As Boolean

            Try
                Dim token1 As New IntPtr
                Dim loggedOn As Boolean = LogonUser(Username, Domain,
Password, 2, 0, token1)
                Dim token2 As New IntPtr
                token2 = token1
                Dim wi As WindowsIdentity
                Dim wp As WindowsPrincipal
                wi = New WindowsIdentity(token2)
                wp = New WindowsPrincipal(wi)
                HttpContext.Current.User = wp
                Return True

            Catch When Err.Number <> 0
                Return False
            End Try
        End Function

What I'm doing wrong, what I'm missing?

Thanks,
Dennis