I have a function that checks if a cookie (by name) exists or not:
Private Function cookieExists(ByVal cName As String) As Boolean
For Each c As HttpCookie In Response.Cookies
If c.Name = cName Then Return True
Next
Return False
End Function
I have a class that handles cookies in an application-specific manner, and I want to consolidate all the cookie-related functions to this class. However, I cannot use this code if I simply move it from the aspx page (where it currently resides) to the aforementioned class because I get the error: 'Name' Response is not declared.
I modified the class to allow the passing of a reference to the Response
object:
Public Function cookieExists(ByVal cName As String, ByRef Response As HttpResponse) As Boolean
For Each c As HttpCookie In Response.Cookies
If c.Name = cName Then Return True
Next
Return False
End Function
My question is: Is there a better way?