I can explain:
When you are working in a webform (either the webform codebehind class or inline script directly in the ASPX file) you are within the context of a class file that derives from System.Web.UI.Page. That class has a visible property named "Server" as well as "Response" and "Request". These properties give you access to live instances of the class behind each property because the expose member instances living in the System.Web.UI.Page class instance created for the page request.
When you create a helper class with methods that you wish to access Server, Response and/or Request you need a valid context of each. The helper class itself is apart from the Page class you are consuming it in so it has no idea of how to get a valid context (unlike any page instance where it's just a property name away). Therefore, you are left with 1 of two options:
1. Your helper method must accept an instance of the class(es) you need to use:
MyHelperClass.HelperSub(oHttpContext As HttpContext)
The helper method can now access the current HttpContext because you require one to be passed into the method.
2. Your helper method uses the .Current property of the HttpContext class which returns a valid HttpContext instance for the executing page request:
System.Web.HTTPContext.Current.Request...
.Current is nothing more than a static/shared member property of type HttpContext. This can be a little confusing because the HttpContext class has a property that returns an instance of itself. This is perfectly legal as long as you don't get yourself into a situation where you get into a infinite loop such as something like this:
Class MyClass
Private _objMyClass As MyClass 'This is OK
Public Sub New()
'This is where we get into trouble
_objMyClass = New MyClass
End Sub
End Class
This would result in a stack overflow because you'd end up with a infinitely recursing constructor.
-
Peter