![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello. I've got the following problem: There is a web application (ASP.NET), that needs to authenticate users against local machine and Active Directory. By default, the application works as ASPNET account (Win2000, XP). When working on ASPNET account the apllication is able to do the following: string path = "WinNT://" + Environment.MachineName + ",computer"; DirectoryEntry entry = new DirectoryEntry(path, username, pwd); try { //force authentication Object o = entry.NativeGuid; //authentication succeeded } catch(...) { //authentication failed } Wnen run as ASPNET account, the code is able to work correctly. However, when run as SYSTEM account, exception is thrown I need to switch to system account, because I also need to authenticate users in Acitive Directory, and ASPNET this time cannnot connect to AD, whereas SYSTEM account can. So, currently I can authenticate users either in local system (when run as ASPNET) or in AD (when run as SYSTEM), bot not concurrently (i.e. I can not do this without restarting the process) SYSTEM ASPNET LOCAL USERS - + DOMAIN USES + - Questions: 1. Is there any way to grant local ASPNET account ability to connect to AD ? 2. Is there any way to allow SYSTEM account to authenticate users against local machine. (The inability seems ridiculous...) (Note: I cannot temporarily use impersonation [SYSTEM is granted right to impersonate someone elese] to check credentials, since the application is a muliti user system and the fraction of time the app would work as somebody else (not system but e.g John.Smith ) would leed to errors. Ok, I might lock entire application functionality when somebody performs logon but this would be hugely ineffective and would require to redesign plenty of code. (The application is pretty complex)) Thanks for help Michal |
#3
| |||
| |||
|
|
ASPNET can definitely talking to Active Directory. However, you may need to supply a domain controller name in your LDAP path as well as valid domain credentials depending on what you are binding to. If you just want to test user names and passwords via a DirectoryEntry bind, this will work fine. Make sure you use the LDAP provider though. |
|
For authenticating against local machine accounts, the WinNT provider is not well suited for this as it has all sorts of problems binding with different credentials in the same process. It would probably be better to call the LogonUser API to test the user's credentials (although you'll need high privileges to call this API in Win2K). LogonUser can also validate domain credentials. |
|
Instead of doing this authentication in code, is it possible for you to leverage IIS security to do this work for you? |
#4
| |||||
| |||||
|
|
"Joe Kaplan (MVP - ADSI)" wrote: ASPNET can definitely talking to Active Directory. However, you may need to supply a domain controller name in your LDAP path as well as valid domain credentials depending on what you are binding to. If you just want to test user names and passwords via a DirectoryEntry bind, this will work fine. Make sure you use the LDAP provider though. currently i'm using the following code to talk to DC: string path = @"LDAP://CN=Users,DC=mydomain,DC=com"; DirectoryEntry entry = new DirectoryEntry(path, domainAndUsername, pwd); DirectorySearcher search =null; try { // Bind to the native AdsObject to force authentication. Object obj = entry.NativeObject; ... } What can I change here to make ASPNET account to connect (and talk) to AD ? |
|
For authenticating against local machine accounts, the WinNT provider is not well suited for this as it has all sorts of problems binding with different credentials in the same process. It would probably be better to call the LogonUser API to test the user's credentials (although you'll need high privileges to call this API in Win2K). LogonUser can also validate domain credentials. I cannot use LogonUser function since this would make the whole application working as another user for fraction of time. If the application |
|
Instead of doing this authentication in code, is it possible for you to leverage IIS security to do this work for you? I can not do that since I'm using forms authentication. The application allows to use application-specific accounts (if somebody does not want to use windows accounts), local machine windows accounts (authentication code example has been provided), and domain-wide accounts, if the machine is conected into domain. |
|
Thank You Michal |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |