How to do automatic Active directory log in if the user logged in domain
Posted by
Amritha444 under
ASP.NET on 7/8/2014 12:16:31 AM |
Points: 75 | Views : 6365 | Status :
[Member]
Hi all
I want to do automatic active directory login when we take a page if the user logged in to the domain . I can login to the system using following code
public bool AuthenticateUser(string domain, string username, string password,string LdapPath, out string Errmsg)
{
Errmsg = "";
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(LdapPath, domainAndUsername, password);
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
LdapPath = result.Path;
string _filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
Errmsg = ex.Message;
return false;
throw new Exception("Error authenticating user." + ex.Message);
}
return true;
}
But if the user already logged to the domain it will not be good to login again . I want user to be redirect to default.aspx if the user logged in domain . ican use the above code if i got username, password of the user logged in to the domain .Is it possible or any other methods for that?
Thankss in Advance
Amritha