我用的是ASP.NET2.0中的MEMBERSHIP,登陆采用的是COOKIES,代码如下:
string userName = TextBox1.Text; 
string password = TextBox2.Text; 
if ((Membership.ValidateUser(userName, password))) { 
 FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddSeconds(60), CheckBox1.Checked, "roles", FormsAuthentication.FormsCookiePath); 
 string encryptedTicket = FormsAuthentication.Encrypt(authTicket); 
 HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); 
 Response.Cookies.Add(authCookie); 

然后在其它页面上采用Page.User.Identity.Name是否为空来确定是否登陆。
可是总是在提交后再刷新一下页面才可以看到登陆成功否,如果不刷新,页面还是显示没有登陆状态。
请问是否采用Page.User.Identity.Name验证登陆方式不正确?

解决方案 »

  1.   

    string userName = TextBox1.Text; 
    string password = TextBox2.Text; 
    if ((Membership.ValidateUser(userName, password))) { 
     FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddSeconds(60), CheckBox1.Checked, "roles", FormsAuthentication.FormsCookiePath); 
     string encryptedTicket = FormsAuthentication.Encrypt(authTicket); 
     HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); 
     Response.Cookies.Add(authCookie); ///-------------------
     Response.Redirect(yourUri);
    }
      

  2.   

    Response.Redirect(yourUri),可是如何在不转向其它页面的情况下可以登陆呢?