System.Web.HttpContext not recognized

有些话、适合烂在心里 提交于 2019-12-22 01:23:54

问题


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.


回答1:


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




回答2:


It was a simple case of not using the right framework, by that I mean the full fat version rather than the default 'light' version.

Right click on the Project and then Properties and make sure the full version of the latest framework is selected ie '.NET Framework 4', not '.NET Framework 4 Client Profile'




回答3:


  1. Make sure the assembly is included
  2. Make sure the reference for the dll is there
  3. Try "resolve" and have the Visual Studio include the reference
  4. Debug, close and restart the application.

This class should work.

UPDATE:

using System.Web

class YourClass {
  public YourClass() {
    HttpContext _context = new HttpContext(your parameters)
  }
}


来源:https://stackoverflow.com/questions/10595543/system-web-httpcontext-not-recognized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!