请教大家: 用.net如何进行AD身份验证?
越详细越好,有范例最好,先谢谢了!
越详细越好,有范例最好,先谢谢了!
解决方案 »
- MVC 404错误页面处理
- 求Open Flash Chart报表控件的饼状和柱状的Demo
- 我的default.aspx总是被加了一句话。
- 可拖动滚动层代码问题
- 怎样才能让网页内容不存到客户机的IE临时文件夹里????
- 又一个关于类的问题,求教....实在是搞不定了..
- asp.net 中怎么嵌入视频
- 为什么C#Web程序要应用那么多namespace而VB只需要引用少数?
- 我写的文章《net未来生活(科幻小说)》在webservice栏目中被固定了!高兴中,散分!
- DropDownList奇怪问题(up有分)
- DataContractJsonSerializer 如何序列化一个匿名对象?
- 求一个sql语句
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.DirectoryServices; namespace ADTest
{public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button btnConnect;
private System.Windows.Forms.TextBox txtUserName;
private System.Windows.Forms.Button btnGetUserDetails;
private System.Windows.Forms.ListBox lstGroups;
private System.Windows.Forms.Button btnGetADGroups;
private System.Windows.Forms.ListBox lstGroupUsers;
private System.Windows.Forms.Label lblGroupNames;
private System.Windows.Forms.Label lblUserName;
private System.Windows.Forms.Label lblGroupUsers;private ArrayList groupList;
private ADUtilities adUtilities = null;
private bool isConnected = false;
public Form1()
{
InitializeComponent();
}/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnConnect = new System.Windows.Forms.Button();
this.txtUserName = new System.Windows.Forms.TextBox();
this.btnGetUserDetails = new System.Windows.Forms.Button();
this.lstGroups = new System.Windows.Forms.ListBox();
this.btnGetADGroups = new System.Windows.Forms.Button();
this.lstGroupUsers = new System.Windows.Forms.ListBox();
this.lblGroupNames = new System.Windows.Forms.Label();
this.lblUserName = new System.Windows.Forms.Label();
this.lblGroupUsers = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnConnect
//
this.btnConnect.Location = new System.Drawing.Point(1040, 56);
this.btnConnect.Name = "btnConnect";
this.btnConnect.Size = new System.Drawing.Size(96, 32);
this.btnConnect.TabIndex = 0;
this.btnConnect.Text = "Not Connected";
this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
//
// txtUserName
//
this.txtUserName.Location = new System.Drawing.Point(112, 56);
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(256, 20);
this.txtUserName.TabIndex = 1;
this.txtUserName.Text = "";
//
// btnGetUserDetails
//
this.btnGetUserDetails.Location = new System.Drawing.Point(112, 104);
this.btnGetUserDetails.Name = "btnGetUserDetails";
this.btnGetUserDetails.Size = new System.Drawing.Size(112, 32);
this.btnGetUserDetails.TabIndex = 2;
this.btnGetUserDetails.Text = "Get Domain Name";
this.btnGetUserDetails.Click += new System.EventHandler(this.btnGetUserDetails_Click);
//
// lstGroups
//
this.lstGroups.Location = new System.Drawing.Point(448, 56);
this.lstGroups.Name = "lstGroups";
this.lstGroups.Size = new System.Drawing.Size(256, 108);
this.lstGroups.TabIndex = 3;
this.lstGroups.DoubleClick += new System.EventHandler(this.lstGroups_DoubleClick);
//
// btnGetADGroups
//
this.btnGetADGroups.Location = new System.Drawing.Point(448, 192);
this.btnGetADGroups.Name = "btnGetADGroups";
this.btnGetADGroups.Size = new System.Drawing.Size(96, 40);
this.btnGetADGroups.TabIndex = 4;
this.btnGetADGroups.Text = "Get Groups";
this.btnGetADGroups.Click += new System.EventHandler(this.btnGetADGroups_Click);
//
// lstGroupUsers
//
this.lstGroupUsers.Location = new System.Drawing.Point(768, 56);
this.lstGroupUsers.Name = "lstGroupUsers";
this.lstGroupUsers.Size = new System.Drawing.Size(224, 108);
this.lstGroupUsers.TabIndex = 5;
//
// lblGroupNames
//
this.lblGroupNames.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblGroupNames.Location = new System.Drawing.Point(456, 16);
this.lblGroupNames.Name = "lblGroupNames";
this.lblGroupNames.Size = new System.Drawing.Size(152, 24);
this.lblGroupNames.TabIndex = 6;
this.lblGroupNames.Text = "Active Directory Groups";
//
// lblUserName
//
this.lblUserName.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblUserName.Location = new System.Drawing.Point(16, 56);
this.lblUserName.Name = "lblUserName";
this.lblUserName.Size = new System.Drawing.Size(72, 24);
this.lblUserName.TabIndex = 7;
this.lblUserName.Text = "User Name:";
//
// lblGroupUsers
//
this.lblGroupUsers.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblGroupUsers.Location = new System.Drawing.Point(768, 16);
this.lblGroupUsers.Name = "lblGroupUsers";
this.lblGroupUsers.Size = new System.Drawing.Size(152, 24);
this.lblGroupUsers.TabIndex = 8;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(1232, 266);
this.Controls.Add(this.lblGroupUsers);
this.Controls.Add(this.lblUserName);
this.Controls.Add(this.lblGroupNames);
this.Controls.Add(this.lstGroupUsers);
this.Controls.Add(this.btnGetADGroups);
this.Controls.Add(this.lstGroups);
this.Controls.Add(this.btnGetUserDetails);
this.Controls.Add(this.txtUserName);
this.Controls.Add(this.btnConnect);
this.Name = "Form1";
this.Text = "Active Directory";
this.ResumeLayout(false);}
#endregion/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}private void btnConnect_Click(object sender, System.EventArgs e)
{
if(!isConnected)
{
try
{
adUtilities = new ADUtilities();
isConnected = true;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
isConnected = false;
}
btnConnect.Text = "Connected";
}
}原文参考
算是在AD中的组策略IE中自动获取用户名和密码的设置。