Log ud funktion virker ikke
Hej..Når jeg logger ind bruger jeg følgende kode:
Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, UserName, DateTime.Now, DateTime.Now.AddMinutes(30), True, p.Roles, FormsAuthentication.FormsCookiePath)
Dim hash As String = FormsAuthentication.Encrypt(ticket)
Dim cookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, hash)
' Set the cookie's expiration time to the tickets expiration time
If (ticket.IsPersistent) Then
cookie.Expires = ticket.Expiration
End If
' Add the cookie to the list for outgoing response
Response.Cookies.Add(cookie)
Dim ReturnURl As String = Request.QueryString("ReturnURL")
If ReturnURl <> "" Then
Response.Redirect(ReturnURl)
Else
Response.Redirect("/Admin/")
End If
Så har jeg i min global.asax:
Protected Sub Application_AuthenticateRequest(ByVal sender As [Object], ByVal e As EventArgs)
If Not (HttpContext.Current.User Is Nothing) Then
If HttpContext.Current.User.Identity.IsAuthenticated Then
If TypeOf HttpContext.Current.User.Identity Is FormsIdentity Then
Dim id As FormsIdentity = CType(HttpContext.Current.User.Identity, FormsIdentity)
Dim ticket As FormsAuthenticationTicket = id.Ticket
' Get the stored user-data, in this case, our roles
Dim userData As String = ticket.UserData
Dim roles As String() = userData.Split(","c)
HttpContext.Current.User = New GenericPrincipal(id, roles)
End If
End If
End If
End Sub
Når jeg så vil logge ud bruger jeg følgende:
Session.Abandon()
Session.Contents.RemoveAll()
HttpContext.Current.User = Nothing
FormsAuthentication.SignOut()
Response.Redirect("/")
Men der sker intet..
Den stiller mig godt nok om til forsiden, men går jeg så ind på de beskyttede sider så kan jeg stadig ændre i alle indstillingerne..
Så den logger mig ikke ud.. Og jeg har prøvet at tømme browserens cache.. uden held..