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)
{
Response.Write("<script>alert('login failed, please confirm username and password!');</script>");
Response.Write("<script>document.location=document.location;</script>");
}
}