日期:2014-05-17  浏览次数:20437 次

asp.net windows 用户认证
快要疯了,请高手指点比较急!开发环境为vs2012
1.我用的是windows身份验证 代码如下,登陆页的.cs代码如下

        protected void Sub_Click(   object sender, EventArgs e)
        {            
            if (TextBox_Name.Text == string.Empty || TextBox_Pwd.Text == string.Empty)
            {
                Response.Write("<script>alert('You don't enter username or password, please input it!');</script>");
                return;
            }

            string ldapPath = "LDAP://" + GetDomainName();
            string domainAndUsername = Environment.UserDomainName + "\\" + TextBox_Name.Text;
            DirectoryEntry entry = new DirectoryEntry(ldapPath, domainAndUsername,    TextBox_Pwd.Text);

            DirectorySearcher search = new DirectorySearcher(entry);

            try
            {
                SearchResult result = search.FindOne();               
         //       Response.Write("<script>alert('login successful');</script>");
                Session["UserID"] = TextBox_Name.Text.Trim();              
                Response.Redirect("index.aspx");

            }
            catch (Exception ex)
            {