Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpContext not available in Class Library

Tags:

I am working on a project where I have a C# class library which needs to use the System.web.HttpContext. I've done this before in another project without problem but now its not working. I'm not sure what I am missing they're both targeting .net 3.5 and I've added the reference System.web and added the directive using System.web.

However, when I try and do HttpContext nothing is found. I've tried using the full path System.web.HttpContext but the only thing that comes up are 3 items related to ASP.

Below are screenshots from the working project intellisense and the non-working intellisense

Below is the working screenshot

working screenshot

and below is the non working screenshot

not working screenshot

Thanks for any help you can provide

like image 388
Boardy Avatar asked Jan 04 '13 01:01

Boardy


People also ask

How do I get HttpContext in .NET core?

ASP.NET Core apps access HttpContext through the IHttpContextAccessor interface and its default implementation HttpContextAccessor. It's only necessary to use IHttpContextAccessor when you need access to the HttpContext inside a service.

What is the HttpContext class?

The HttpContext encapsulates all the HTTP-specific information about a single HTTP request. When an HTTP request arrives at the server, the server processes the request and builds an HttpContext object. This object represents the request which your application code can use to create the response.

What is HttpContext MVC?

HttpContext is a type which has a static Current property that you're using to get the current context. There isn't a System. Web. Mvc.


2 Answers

This means that either you are using a Client Profile as the Target Framework or the reference to System.Web was not added correctly.

like image 158
competent_tech Avatar answered Sep 20 '22 22:09

competent_tech


Despite your comment that you've added reference to System.Web to the project it is still most likely reason of what you are seeing.

The classes you see are coming from System.Dll, not System.Web.Dll.

like image 21
Alexei Levenkov Avatar answered Sep 22 '22 22:09

Alexei Levenkov