快要疯了,请高手指点比较急!开发环境为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后才能正常)请高手指点,或推荐相关的参考资料!

解决方案 »

  1.   

    1、HttpContext.Current.User.Identity.Name问题
    你确认登录成功后,并没有对于该用户的Authenticate做任何设置。我认为,应该有类似于HttpContext.Current.IsAuthencitae = true, HttpContext.Current.User = new User{}之类的代码。代码细节可能不是这样,但大致思路是这样。2.你退出后能够不经登录就能进入其他页,可能的原因有,sesssion没有清理干净,或者sAuthencitae没有设置为false,或者有cookie什么的。