C# System.Web.HttpContext 无法识别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10595543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 14:25:18  来源:igfitidea点击:

System.Web.HttpContext not recognized

c#asp.netvisual-studio-2008

提问by Anna T

I have a ASP.NET with C# web application. One of the classes I created needs to use HttpContext.

我有一个带有 C# web 应用程序的 ASP.NET。我创建的类之一需要使用 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).

根据http://msdn.microsoft.com/en-us/library/system.web.httpcontext(v=vs.90).aspx, HttpContext 存在于 .NET 3.5 的 System.Web 命名空间中(这是版本我已经安装了)。

However, when I write HttpContext. --> I don't see autocomplete. Which is what tells me that HttpContext is not recognized.

但是,当我编写 HttpContext. --> 我没有看到自动完成。这就是告诉我无法识别 HttpContext 的原因。

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;

我做了功课并寻找了常用的解决方案: 1. 我添加了 System.Web 参考(通过右键单击参考 -> 选择 .NET 选项卡和特定参考)。2. 我还确保在类中包含这一行: 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.

请告诉我我还能做什么。如果一切顺利,当我写 HttpContext. - 我应该看到一个下拉列表,并且能够从几个属性/元素中选择“当前”。我是 C# 和 Visual Studio (2008) 的新手,但我认为自动完成不能很好地表明缺少引用/命名空间/加载错误/其他任何东西。

采纳答案by CodeNotFound

The constructor is rarely used when you want to instantiate the HttpContextclass. I always use the static property HttpContext.Currentwhich is the current instance used by all the ASP.Net application.

当您要实例化HttpContext类时,很少使用构造函数。我总是使用静态属性HttpContext.Current,它是所有 ASP.Net 应用程序使用的当前实例。

For using it make sure you already add reference to the System.Web.dll assembly and import the System.Webnamespace

要使用它,请确保您已经添加对 System.Web.dll 程序集的引用并导入System.Web命名空间

回答by iefpw

  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.
  1. 确保包含组件
  2. 确保 dll 的引用在那里
  3. 尝试“解决”并让 Visual Studio 包含参考
  4. 调试、关闭并重新启动应用程序。

This class should work.

这个类应该工作。

UPDATE:

更新:

using System.Web

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

回答by userSteve

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'

右键单击项目,然后单击属性并确保选择了最新框架的完整版本,即“.NET Framework 4”,而不是“.NET Framework 4 Client Profile”