When I write inline code on a aspx page using Page.Response.Cookies() to read a cookie, everything works fine, as in the following code.
Dim x As Object = Request.Cookies("thing")
If x Is Nothing Then
CurrentValue.Text = "No Cookie Defined"
Else
CurrentValue.Text = Request.Cookies("thing").Value
End If
However, I wanted to move the code to a shared method so I do not have access to the instance Page class any more so I used the shared method from System.Web.HttpContext.Current.Request.Cookies(). This, however, did not yeald the same results as the oringonal code (Aka: did not work). See the following code
Private Shared Function ReadCookieOr(ByVal CookieName As String, ByVal NothingReturnValue As String) As String
Dim x As Object = System.Web.HttpContext.Current.Response.Cookies(Co okieName)
If x Is Nothing Then
Return NothingReturnValue
Else
Return System.Web.HttpContext.Current.Request.Cookies(Coo kieName).Value
End If
End Function
Here are my issues:
1. How do I determine if the Shared(or static) Cookies method contains a value, like I do in the inline code (using: If x Is Nothing)
2. If I do need assign a reference of this class to an object, how do I cast that object back to origonal class (I guess in VB.net it would use ctype...)
3. In the above example, why does System.Web.HttpContext.Current.Request.Cookies(Coo kieName).Value never return a value that was set earlier (but the instance method does)
Thank you for your help
Earl