如何使用ASP.NET代码查看、修改AD用户信息

以下代码是本人为公司编写的AD帐户信息修改的程序代码,包括头像(二进制)的上传与修改;

设计过程大致如下:

1.选择对应AD服务器并验证、登陆; --因本公司有多个不同AD子域,需要各自管理对应AD域;

2.查询帐户;

3.修改信息并提交保存; --- 如邮件、 别名、部门、头像等;

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.DirectoryServices;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Xml;

namespace ADHelp10
{
    public partial class _Default : System.Web.UI.Page
    {

        public string company = "", department = "", description = "", displayName = "", telephoneNumber = "", title = "", distinguishedName = "", office = "", email = "", userpassword = "";
        public string username_admin ="",password_admin="";

 

        protected void Page_Load(object sender, EventArgs e)
        {

 
            //初始化菜单-- 供用户选择不同域,通XML获取;

     
        }

           public void IsAuthenticated_admin(string id)

       {

            //验证,请自行添加;

       }

 

            using (DirectoryEntry de0 = new DirectoryEntry())
            {
                de0.Path = LDAP2;
                de0.Username = @"" + this.Session["domain"].ToString().Trim() + "//" + id;
                de0.Password = password;
                DirectorySearcher MySearch = new DirectorySearcher(de0);
                MySearch.Filter = "(sAMAccountName=" + id + ")";

                try
                {
                    SearchResultCollection results = MySearch.FindAll();

                    if (results.Count > 0)
                    {
                        this.Panel2.Visible = false;
                        this.Panel3.Visible = true;
                        //this.usersearch.Text = id;
                    }
                    else
                    {
                        this.Response.Write("<script language='javascript'>alert('提示:AD授权验证失败!');history.go(-1);</script>");  

                    }


                }

                catch (Exception)
                {
                    //Response.Write(ex);
                    this.Response.Write("<script language='javascript'>alert('提示:服务器无法连接!');history.go(-1);</script>");  
                   
                }

            }


        }

 

        //登陆,并验证

        protected void Button1_Click(object sender, EventArgs e)
        {
           this.Session["username"] = (this.Username.Text.Trim().ToLower());
            this.Session["password"] = this.Password.Text.Trim();
            this.Session["LDAP2"] = this.DropDownList1.SelectedValue.Trim();
            //通过LDAP2值,确定其他session,LDAP1和domain;

            DataRow row = Session[DropDownList1.SelectedIndex.ToString()] as DataRow;

            this.Session["LDAP1"] = row["LDAP1"];
            this.Session["domain"] = row["domain"];

  

           //验证授权
            IsAuthenticated_admin(this.Username.Text.Trim().ToLower());
            IsAuthenticated(this.Username.Text.Trim().ToLower(), this.Password.Text.Trim(), this.DropDownList1.SelectedValue.Trim());
 

 </

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值