Click here to Skip to main content
15,905,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am implementing windows authentication in MVC4
how to authenticate active directory users in my asp.net on another server on same network?
Posted
Comments
Member 10434230 17-Dec-13 5:35am    
can you elaborate more on "how to authenticate active directory users in my asp.net on another server on same network?"
[no name] 17-Dec-13 8:24am    
Thanks for your reply. I want to authenticate users using active directory of the another domain on the same network.
Member 10434230 17-Dec-13 8:30am    
So, what i understand here is that:
1. you want to do AD authentication (lets name the domain having users as Domain_1)
2. your application will be deployed in other Domain (say e.g Domain_2)
3. the Domain_1 will be accessible to your application

Please confirm the above deployment scenario for your application.
[no name] 17-Dec-13 8:53am    
Yes you exactly got my point.

1 solution

Below is the sample for LDAP authentication (you can take more details from http://support.microsoft.com/kb/316748[^]):

Just pass valid Domain name (as you said it should be reachable), you need not to worry whether you application is lying in which domain.


public bool IsAuthenticated(String domain, String username, String pwd)
{
String domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);


try
{ //Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;


DirectorySearcher search = new DirectorySearcher(entry);


search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();


if(null == result)
{
return false;
}


//Update the new path to the user in the directory.
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}


return true;
}
 
Share this answer
 
Comments
[no name] 18-Dec-13 1:02am    
Using this function give me 'The server is not operational' error. manually I can login using this ID
Member 10434230 18-Dec-13 1:36am    
Please take out some time and read the article at: http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C

within this article: search for "Authenticate a User Against the Directory", see if you are passing correct values to the parameters

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900