在C#程序启动时AD登录 [英] AD login at program start in C#

查看:164
本文介绍了在C#程序启动时AD登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。

我已经在基于AD服务器的小型软件上工作了一段时间。

I have been working for some time on a minor AD Server based software.

这是一个从USB密钥获取流程安装文件的程序从我的服务器到客户PC。

It's a program there runs from a USB key get stream install files from my server to the costumer PC.

现在我测试了我的"软件"。在非AD计算机上无法连接到服务器上的文件夹,因为非登录错误(客户PC不通过AD用户帐户登录)

The thing is now that i tested my "software" on a non AD computer and can't connect to the folder on the server becouse of a non login error (the costumer PC don't login via an AD user account)

所以我的问题简而言之:

So my question in short:

我可以在我的form1启动之前弹出AD登录promt吗?也许是通过UserControle.CS?

Can i make a AD login promt to pop up before my form1 starts? maybe via the UserControle.CS?

我一直在网上搜索,只是更容易理解..

I have been seaching the net and only got much more confuced..

推荐答案


System.DirectoryServices名称空间
提供从托管代码轻松访问Active Directory 。

The System.DirectoryServices namespace provides easy access to Active Directory from managed code.

using System.DirectoryServices; 
  
    //srvr = ldap server, e.g. LDAP://domain.com 
    //usr = user name 
    //pwd = user password 
    public bool IsAuthenticated(string srvr, string usr, string pwd) 
    { 
        bool authenticated = false; 
  
        try 
        { 
            DirectoryEntry entry = new DirectoryEntry(srvr, usr, pwd); 
            object nativeObject = entry.NativeObject; 
            authenticated = true; 
        } 
        catch (DirectoryServicesCOMException cex) 
        { 
            //not authenticated; reason why is in cex 
        } 
        catch (Exception ex) 
        { 
            //not authenticated due to some other exception [this is optional] 
        } 
        return authenticated; 
    } 

此外,请参阅以下线程。

In addition, please refer follow  threads.

来自ASP .NET的Active Directory身份验证 

如何通过以下方式对Active Directory进行身份验证使用表单身份验证和Visual Basic .NET

希望它对您有所帮助。

最好的问候,

Bob

通过活动目录


这篇关于在C#程序启动时AD登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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