views:

28

answers:

1

I would like to do this: Dim str As String = class.isGuest("yes") but it won't work.

Public Property IsGuest(ByVal guestStatus As String) As String
    Get
        Dim guestCookie As New HttpCookie("g")

        For Each key As String In Context.Response.Cookies.Keys
            If key = MYACCOUNT_SESSION_COOKIE_NAME Then
                guestCookie = Context.Response.Cookies.Item(MYACCOUNT_SESSION_COOKIE_NAME)
                Exit For
            End If
        Next

        guestCookie.Value = guestStatus
        Response.Cookies.Add(guestCookie)

        Return guestCookie.Value.ToString
    End Get
    Set(ByVal value As String)
        Dim guestCookie As New HttpCookie("g")

        guestCookie.Value = value
        Response.Cookies.Add(guestCookie)
    End Set
End Property
A: 

There are a few issues in your code, but I think the primary problem is that you are setting / creating a cookie called "g", but you are then attempting to retrieve a cookie called MYACCOUNT_SESSION_COOKIE_NAME.

You can also simplify your code by replacing your loop through the keys with a call to the property on the cookie collection that does the same thing.

Public Property IsGuest(ByVal guestStatus As String) As String 
    Get 
        Return Context.Response.Cookies(MYACCOUNT_SESSION_COOKIE_NAME).Value
    End Get 
    Set(ByVal value As String) 
        Response.Cookies.Add(New HttpCookie(MYACCOUNT_SESSION_COOKIE_NAME, value) 
    End Set 
End Property 
Jason Berkan