For a class library, I think you can pass the corresponding variables / objects through the constructor or methods. This is good practice because your class library will not be broken if you reference it in a console application without httpcontext, for example.
If you use a controller method, you can simply use a request or response.
source share