I have a ASP.NET with C# web application. One of the classes I created needs to use HttpContext.
According to http://msdn.microsoft.com/en-us/library/system.web.httpcontext(v=vs.90).aspx, HttpContext exists in the System.Web namespace in .NET 3.5 (which is the version I have installed).
However, when I write HttpContext. --> I don't see autocomplete. Which is what tells me that HttpContext is not recognized.
I did my homework and looked for usual solutions: 1. I added System.Web reference (by right clicking References -> choosing .NET tab and the particular reference). 2. I also made sure to include this line in the class: using System.Web;
Please tell me what else can I do. If all goes well, when I write HttpContext. - I am supposed to see a drop down list and be able to choose "Current" from there amongst several attributes/elements. I am new with C# and Visual Studio (2008) but I think Autocomplete not working well is a good indicator of a lacking reference/namespace/load errors/whatever else.
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.
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.
You can't use System. Web in . NET Core to access HttpContext. While it may be technically possible to add a reference to System.
The best way to get a look under the hood is to create a project and open the References folder. Inside, you'll see all the default libraries, including SYSTEM. WEB. If you right-click a DLL, you can choose "View In Object Browser", which will then open the DLL so you can explore all the stuff inside.
The constructor is rarely used when you want to instantiate the HttpContext class. I always use the static property HttpContext.Current which is the current instance used by all the ASP.Net application.
For using it make sure you already add reference to the System.Web.dll assembly and import the System.Web namespace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With