Using VB 2005. I've got to be able to connect to a server app in both a domain and a workgroup scenario using IIS. The domain code passes Windows Authentication. The workgroup code requires the user to enter their username and password. Checking "local impersonation" in the ASP.NET Configuration Settings lets the code for domain access to work, but not the workgroup. Unchecking "local impersonation" breaks the domain code. Anybody have code for both. Thanks.
Here's the two functions:
'domain
Public Function GetUsersGroups(ByVal ServerName As String, ByVal DomainName As String, ByVal UserName As String) As String()
Dim iCount As Integer = 0
Dim szGroups() As String = Nothing
Dim Computer
Dim oGroup
Dim Group
Dim groupnames As String = ""
Dim filter As System.Object() = {"group"}
Computer = GetObject("WinNT://" & ServerName)
Computer.Filter = filter
For Each Group In Computer
oGroup = GetObject("WinNT://" & ServerName & "/" & Group.name & ",group")
If oGroup.IsMember(GetObject("WinNT://" & DomainName & "/" & UserName & ",user").adspath) Then
ReDim Preserve szGroups(iCount)
szGroups(iCount) = Group.name
iCount += 1
End If
Next
Return szGroups
End Function
'workgroup
Public Function AuthenticateLogin(ByVal Workgroup As String, ByVal username As String, ByVal password As String) As Boolean
Try
Dim objNS = GetObject("WinNT:")
Dim filter As System.Object() = {"groups"}
Dim objContainer = objNS.OpenDSObject("WinNT://" & Workgroup, username, password, 1)
objContainer.filter = filter
For Each objUser As Object In objContainer
'Console.WriteLine(objUser.name)
Next
Return True
Catch Err As Exception
Return False
End Try
End Function