asp.net windows 用户认证

没事就来看看 没事就来看看 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
快要疯了,请高手指点比较急!开发环境为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>");
}

}

登陆后访问其它页时发现:(其它页Page_load()中1.Request.IsAuthenticated返回的一直是false,并且HttpContext.Current.User.Identity.Name也为空,取不到用户名。2.改用Session["UserID"] == null方法确定是否用户通过验证发现这个方法在IE上是正常的,但是在sougo上是不正常的。另在sougo发现,当第一次访问该网页的时候不登陆是不能直接进入其它页的,当第一次登陆成功退出以后再进入的时候就不需要登陆页面就可以直接访问其它页。然后在vs2012中clean solution后 再次访问就的通过登陆后才能进入其它页,就是登陆成功退出后一直需要clean solution后才能正常)

请高手指点,或推荐相关的参考资料!
...全文
评论 2
收藏 已收藏
分享
返回顶部
没事就来看看
.NET社区 62,275 成员 668,968 内容