Accessing ASP Cookie in ASP.Net using VB.NET

Get the SessionCookie

With the ASP application web server set a cookie with a name that starts with ASPSESSION. This is the ASP Session cookie. All subsequent requests sent from the client to the server will include the ASP Session cookie along with the request. This cookie allows IIS to associate the request with a specific session object that is stored on the server.

If you have ASP and ASP.NET applications running in the same virtual directory means having ASP & ASPX pages in same virtual directory. An ASP session and an ASP.NET session have been established with the same server, the browser will send both the ASP and ASP.NET cookies with each request.

Following code tells how to find ASP cookie from ASP.Net for above seen.

Public Class ASPSessionVar

Dim oContext As HttpContext

'Constructor

Public Sub New(ByVal oContextIn As HttpContext)
oContext = oContextIn
End Sub

'Function

Public Function blnGetSessionCookie(ByRef ASPCookieName As String, ByRef ASPCookieValue As String) As Boolean
Dim
i As Integer
Dim
Ck As HttpCookie
Dim CkArray() As String = oContext.Request.Cookies.AllKeys
CkName = ""
CkValue = ""
i = 0

While i < CkArray.Length

Ck = oContext.Request.Cookies(CkArray(i))

If (ck.Name.StartsWith("ASPSESSION")) Then

 

CkName = Ck.Name

CkValue = Ck.Value

Return True

End If

End While

Return False

 

End Function

End Class

Up Next
    Ebook Download
    View all
    Learn
    View all