如果用户登录域,如何进行自动Active Directory登录 [英] How to do automatic Active directory log in if the user logged in domain

查看:118
本文介绍了如果用户登录域,如何进行自动Active Directory登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



如果用户登录到域,我们想要在页面上进行自动活动目录登录。我可以使用以下代码登录系统

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;

        }



但是如果用户已登录到域,则再次登录将不会有好处。如果用户登录域,我希望用户重定向到default.aspx。 ican使用上面的代码,如果我有用户名,登录到域的用户的密码。是否可能或任何其他方法?



提前感谢

Amritha


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

推荐答案

这篇关于如果用户登录域,如何进行自动Active Directory登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆