forced all / specific user logout (cookies) RRS feed

  • Question

  • User944339287 posted

    Hi guys. The following is my code for successful login.

    May i know how can i force logout all the logged-in user by clicking a button? or just logout a specific user? (by system_UID) TQ

                Dim myCookie As New HttpCookie("WebtivateUserInCakes")
                myCookie.Values.Add("system_UID", DT.Rows(0).Item("UID"))
                myCookie.Values.Add("system_name", DT.Rows(0).Item("name1"))
                myCookie.Values.Add("system_username", DT.Rows(0).Item("username"))

    Tuesday, April 23, 2019 9:18 AM

All replies

  • User-1174608757 posted

    Hi kengkit,

    According to your description, firstly you should know that cookie is saved in browser side which means user side but not server.So it is impossible for server to make any changes so that we could delete all the cookies in users' browsers.So in your situation,only if users click the button, it could remove his own cookie.

    You could remove specific cookie by using code as below,you could first create a new cookie which name is same as cookie you want to clear, and set it as null. Lastly , you could add this cookie and it will cover the original cookie.Here is the code ,I hope it could help you.

    Protected Sub Button1_Click(sender As Object, e As EventArgs)
        If HttpContext.Current.Request.Cookies("WebtivateUserInCakes") IsNot Nothing Then
            Dim aCookie As HttpCookie = HttpContext.Current.Request.Cookies("WebtivateUserInCakes")
            aCookie.Expires = DateTime.Now.AddDays(-10)
            aCookie.Value = ""
        End If
    End Sub

     Best Regards


    Wednesday, April 24, 2019 2:00 AM