我用HttpContext.Current.User.Identity.IsAuthenticated这个变量来判断用户是否登录,那么登录之后这个变量的值会自动改变吗?
如果会改变,那它是怎样改变的。
谢谢!

解决方案 »

  1.   

    YES 会的
    这个只用来改写Profile或membership时候用~~~~ 
    内部机制API,建议非微软员工不使用它,哈哈~~~~~~~~~
    开个玩笑啦 ~~~  
      

  2.   

    但是一次登录了,在下次开机前,它的值都是为ture的,怎样可以让它在浏览器关闭后又变回false呢?
      

  3.   


    if 用户名密码正确 then
    Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1,Name, DateTime.Now, DateTime.Now.AddDays(1),False,GroupNames,FormsAuthentication.FormsCookiePath)
    Dim hash As String = FormsAuthentication.Encrypt(ticket)
    Dim cookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, hash)
    If (ticket.IsPersistent) Then cookie.Expires = ticket.Expiration
    HttpContext.Current.Response.Cookies.Add(cookie)
    end if
    Public Sub Logout
    Dim cookie As HttpCookie
    cookie = FormsAuthentication.GetAuthCookie(Page.User.Identity.Name, True)
    cookie.Expires = New DateTime(0)
    HttpContext.Current.Response.Cookies.Add(cookie)
    FormsAuthentication.SignOut()
    Page.Response.Redirect("/admin/login.aspx")
    End Sub
    其中FormsAuthenticationTicket有很多有用的参数,建议楼主去查阅一下MSDN再来。