Public Function GetSessionVar(ByVal pASPSessionVar As String) As String
        Dim pASPCookieName As String
        Dim pASPCookieValue As String
        If Not GetSessionCookie(pASPCookieName, pASPCookieValue) Then
            Return ""
        End If
        Dim pMyRequest As HttpWebRequest = CType(WebRequest.Create(mASPSessionVarASP + "?SessionVar=" + pASPSessionVar), HttpWebRequest)
        pMyRequest.Headers.Add("Cookie: " + pASPCookieName + "=" + pASPCookieValue)
        'pMyRequest.RequestUri()
        'pMyRequest.Timeout = 10000
        'pMyRequest.KeepAlive = False
        'pMyRequest.Method = "POST"
        Dim pMyResponse As HttpWebResponse = CType(pMyRequest.GetResponse(), HttpWebResponse)
        Dim pReceiveStream As Stream = pMyResponse.GetResponseStream()
        Dim pReadStream As StreamReader = New StreamReader(pReceiveStream, System.Text.Encoding.UTF8)
        Dim pStrResponse As String = pReadStream.ReadToEnd()
        pReadStream.Close()
        pMyResponse.Close()
        Return pStrResponse
    End Function
    Private Function GetSessionCookie(ByRef pASPCookieName As String, ByRef pASPCookieVal As String) As Boolean
        Dim pIntCnt As Integer
        Dim pMyCookie As HttpCookie
        pASPCookieName = ""
        pASPCookieVal = ""
        Dim pCookieArray As String() = mOcontext.Request.Cookies.AllKeys
        For pIntCnt = 0 To pCookieArray.Length - 1
            pMyCookie = mOcontext.Request.Cookies(pCookieArray.GetValue(pIntCnt))
            If pMyCookie.Name.StartsWith("ASPSESSION") Then
                pASPCookieName = pMyCookie.Name
                pASPCookieVal = pMyCookie.Value
                Return True
            End If
        Next
        Return False
    End Function

Like it on Facebook, +1 on Google, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet