ARTICLE

Accessing ASP Cookie in ASP.Net

Posted by Pragati Articles | ASP.NET using VB.NET December 21, 2006
This article shows how to access ASP Cookie in ASP.Net.
 
Reader Level:

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

share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor