1
Vote

How to Logout from f connect using Facebook Toolkit

description

I am trying able to login to my website using f-connect, but i am able to logout. I am trying to write the code from my code behind page and not the javascript.
 
Imports facebook
Imports facebook.web
 
Partial Class SignOut
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Try
        'Logout for Facebook Connect
        Dim api As New API()
        api.SessionKey = ConnectAuthentication.SessionKey
        If ConnectAuthentication.isConnected() Then
            ConnectAuthentication.LogoutFacebook("session_key")
        End If
 
        Response.Redirect("default.aspx")
    Catch ex As Exception
        Throw ex
    End Try
End Sub
End Class
 
And the class file is as below.....
 
Imports Microsoft.VisualBasic
 
Public Class ConnectAuthentication
 
Public Sub New()
End Sub
 
Public Shared Function isConnected() As Boolean
    Return (SessionKey IsNot Nothing AndAlso UserID <> -1)
End Function
 
Public Shared ReadOnly Property ApiKey() As String
    Get
        Return ConfigurationManager.AppSettings("APIKey")
    End Get
End Property
 
Public Shared ReadOnly Property SecretKey() As String
    Get
        Return ConfigurationManager.AppSettings("Secret")
    End Get
End Property
 
Public Shared ReadOnly Property SessionKey() As String
    Get
        Return GetFacebookCookie("session_key")
    End Get
End Property
 
Public Shared ReadOnly Property UserID() As Integer
    Get
        Dim userID__1 As Integer = -1
        Integer.TryParse(GetFacebookCookie("user"), userID__1)
        Return userID__1
    End Get
End Property
 
Private Shared Function GetFacebookCookie(ByVal cookieName As String) As String
    Dim retString As String = Nothing
    Dim fullCookie As String = ApiKey & "_" & cookieName
 
    If HttpContext.Current.Request.Cookies(fullCookie) IsNot Nothing Then
        retString = HttpContext.Current.Request.Cookies(fullCookie).Value
    End If
    Return retString
End Function
 
Public Shared Function LogoutFacebook(ByVal cookieName As String) As String
    Dim retString As String = Nothing
    Dim fullCookie As String = ApiKey & "_" & cookieName
 
    If HttpContext.Current.Request.Cookies(fullCookie) IsNot Nothing Then
        retString = HttpContext.Current.Request.Cookies(fullCookie).Expires()
    End If
 
    Return retString
End Function
End Class
 
Can anybody please help me out

comments