Click here to Skip to main content
15,608,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);



                // Bind to the native AdsObject to force authentication.

                Object obj = entry.NativeObject;

                DirectorySearcher search = new DirectorySearcher(entry);

                search.Filter = "(SAMAccountName=" + username + ")";


                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

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