在 .NET 3.5 和 Visual Studio 2008 中找不到 HttpContext

发布于 2024-09-16 16:50:58 字数 410 浏览 10 评论 0原文

我使用了此处中的代码,出现以下错误: 无法使用 HttpContext.Current.Server.MapPath()

在 Visual Studio 2008 中,当您缺少引用时,ContextMenuEntry“解决”是否可以帮助您?

我已经发现 HttpContext 不是我的 IDE 中 System.Web 的成员。 根据帮助>信息我正在使用 .NET 3.5 SP1。

我如何让它运行?

在这种情况下你通常会如何反应?您在 msdn.com 上寻找什么内容?

I used code from here and I get the following error:
Can't use HttpContext.Current.Server.MapPath()

In Visual Studio 2008 does the ContextMenuEntry "Solve" help you when you have missing references?

I already found out that HttpContext is not a member of System.Web in my IDE.
According to Help > Info I am using .NET 3.5 SP1.

How do I get that running?

How do u usually react in this situation? What stuff do u look for in msdn.com?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

只涨不跌 2024-09-23 16:50:58

在这种情况下我会做的是在 MSDN(或 Google)上查找 HttpContext。我这样做了,它说它在 System.Web 中。因此,请确保您的项目具有对 System.Web 的引用。

“添加引用”菜单项

“添加引用”对话框中的“System.Web”

...然后它似乎可以工作:

HttpContext 现在可用.

What I would do in that situation is look on MSDN (or Google) for HttpContext. I did that, and it says it’s in System.Web. So make sure your project has a reference to System.Web.

“Add Reference” menu item

“System.Web” in the Add Reference dialog

... and then it seems to work:

HttpContext is now available.

怪我太投入 2024-09-23 16:50:58

您可以查看 HttpContext 类的文档 ,它告诉您它位于 System.Web 命名空间中的 System.Web.dll 库中。

因此,要使用它,您需要引用 System.Web.dll 库,并且需要 using System.Web; 语句,或者使用完全限定名称System.Web.HttpContext.Current.Server.MapPath

但是,您确定要使用 MapPath 方法吗?该方法获取文件的 Web 引用的物理路径。如果 CSV 文件的路径是 Web 引用,例如 "/data/items.csv",那么您需要使用 MapPath 方法,但如果您有物理路径,例如 "C:\mydata\items.csv" 那么您不想转换它。

此外,MapPath 仅在您实际处于具有 HTTP 上下文的 Web 应用程序中时才起作用。

You can look in the documentation for the HttpContext class, and it tells you that it's in the System.Web namespace, in the System.Web.dll library.

So, to use it you need a reference to the System.Web.dll library, and you either need a using System.Web; statement, or use the fullly qualified name System.Web.HttpContext.Current.Server.MapPath.

However, are you sure that you want to use the MapPath method? The method gets the physical path of a web reference to a file. If the path to your CSV file is a web reference, for example "/data/items.csv" then you want to use the MapPath method, but if you have a physical path like for example "C:\mydata\items.csv" then you don't want to convert it.

Also, the MapPath only works if you actually are in a web application, where there is a HTTP context.

心欲静而疯不止 2024-09-23 16:50:58

Timwi 说得对,但为了完整性。不,VS 没有内置“求解”功能,但某些附加组件已部分添加了此功能。例如,Resharper 将添加添加引用并在需要时使用的选项 - 但它必须之前已在解决方案中引用过,因此它无法解决最初的查找问题。

Timwi has it right, but for completeness. No, VS does not have the 'Solve' capability built in, however this functionality has been partially added by some add-ons. For example, Resharper will add the option to add the reference and using when needed -- but it does have to have been referenced before in the solution so it doesn't solve the initial find problem.

别低头,皇冠会掉 2024-09-23 16:50:58

这是一个没有使用正确框架的简单情况,我的意思是完整的胖版本而不是默认的“轻”版本。

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

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'

老娘不死你永远是小三 2024-09-23 16:50:58

尝试在项目中添加对 System.Web 的引用。

HttpContextSystem.Web 的成员。

http://msdn.microsoft.com/en-us/库/system.web.httpcontext.aspx

Try to add a reference to System.Web in your project.

HttpContext is a member of System.Web.

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文