logo       

Re: check domain controller: msg#00116

windows.devel.dotnet.web

Subject: Re: check domain controller

Dang this list is slow. I wrote this on Monday and it just showed up. Ok
this is what I came up with. My friend suggested a nested
try/catch..never done one before. This will build but does anybody have
any suggestions to make it prettier or see anything wrong?

Public Function GetUserEntry(ByVal strDomainLookup As String, ByVal
strUserID As String, ByVal strAltDomainLookup As String)As
DirectoryEntry
Dim strUserName As String

Try
'Trim off the domain prefix from the user id
strUserName = strUserID.Substring(strUserID.IndexOf("\") +
1)

'Create a directory entry object to search against
Dim de As DirectoryEntry = New
DirectoryEntry(strDomainLookup, ADUser, ADPwd,
AuthenticationTypes.Secure)

'Define a search to look for the given user
Dim mySearcher As DirectorySearcher = New
DirectorySearcher(de)
mySearcher.SearchScope = SearchScope.Subtree
mySearcher.Filter =
"(&(objectCategory=user)(samAccountName=" & strUserName & "))"

mySearcher.PropertiesToLoad.Add("memberOf")
mySearcher.ReferralChasing = ReferralChasingOption.All

Dim myResult As SearchResult
myResult = mySearcher.FindOne()
GetUserEntry = myResult.GetDirectoryEntry()
Catch exc As Exception
Try
'Trim off the domain prefix from the user id
strUserName = strUserID.Substring(strUserID.IndexOf("\")
+ 1)

'Create a directory entry object to search against
Dim de As DirectoryEntry = New
DirectoryEntry(strAltDomainLookup, ADUser, ADPwd,
AuthenticationTypes.Secure)

'Define a search to look for the given user
Dim mySearcher As DirectorySearcher = New
DirectorySearcher(de)
mySearcher.SearchScope = SearchScope.Subtree
mySearcher.Filter =
"(&(objectCategory=user)(samAccountName=" & strUserName & "))"

mySearcher.PropertiesToLoad.Add("memberOf")
mySearcher.ReferralChasing = ReferralChasingOption.All

Dim myResult As SearchResult
myResult = mySearcher.FindOne()
GetUserEntry = myResult.GetDirectoryEntry()
Catch ex As Exception
Dim evtLog As New System.Diagnostics.EventLog("CSIMS",
System.Environment.MachineName, "CSIMS.Security.GetUserEntry")
evtLog.WriteEntry("strDomainLookup: " +
strAltDomainLookup + vbCrLf + "strUserName: " + strUserName + vbCrLf +
vbCrLf + "The failover failed" + vbCrLf + vbCrLf + exc.Message + vbCrLf
+ vbCrLf + exc.StackTrace, System.Diagnostics.EventLogEntryType.Error,
0)
End Try
End Try
End Function

Bob Wakefield
"Don't be so concerned with living that you forget to live"
913.905.5112
-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:DOTNET-WEB@xxxxxxxxxxxxxxxxxxx] On Behalf Of William Bartholomew
Sent: Monday, June 20, 2005 6:12 PM
To: DOTNET-WEB@xxxxxxxxxxxxxxxxxxx
Subject: Re: [DOTNET-WEB] check domain controller

Can you just use a Try/Catch around the first one?

On 6/21/05, Wakefield, Bob <Wakefield_Bob@xxxxxxxxxxxxxxxxxxxx> wrote:
> I have an app that I maintain that authenticates off AD. Problem is if
a
> domain controller goes down the app does not failover. I need a way to
> say
> Check this: LDAP://domainController1/DC=xxx,DC=xxx,DC=xxx
> If this does not work go here:
> LDAP://domainController2/DC=xxx,DC=xxx,DC=xxx
>
> I'm not sure how to do that.
>
> Bob Wakefield
> "Don't be so concerned with living that you forget to live"
> 913.905.5112
>
> ===================================
> This list is hosted by DevelopMentor(r) http://www.develop.com
>
> View archives and manage your subscription(s) at
http://discuss.develop.com
>


--

Regards,

William D. Bartholomew
http://blog.bartholomew.id.au/

===================================
This list is hosted by DevelopMentor(r) http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise