Access Response Object in ASP.NET Class

I have a function that checks if a cookie exists (by name):

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 processes cookies depending on the application, and I want to combine all the cookie related functions for this class. However, I cannot use this code if I simply move it from the aspx page (where it is currently) to the aforementioned class, because I get the error: 'Name' Response is not declared.I modified the class to allow the link to be passed to : Response

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?

+6
source share
2 answers
HttpContext.Current.Response
HttpContext.Current.Request
+13
source

HttpContext.Current Ambient Context, Response . .

, , Ambient Context :

http://aabs.wordpress.com/2007/12/31/the-ambient-context-design-pattern-in-net/

+2

All Articles