在 .NET 3.5 和 Visual Studio 2008 中找不到 HttpContext
我使用了此处中的代码,出现以下错误: 无法使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在这种情况下我会做的是在 MSDN(或 Google)上查找
HttpContext
。我这样做了,它说它在System.Web
中。因此,请确保您的项目具有对 System.Web 的引用。...然后它似乎可以工作:
What I would do in that situation is look on MSDN (or Google) for
HttpContext
. I did that, and it says it’s inSystem.Web
. So make sure your project has a reference toSystem.Web
.... and then it seems to work:
您可以查看 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 theSystem.Web.dll
library.So, to use it you need a reference to the
System.Web.dll
library, and you either need ausing System.Web;
statement, or use the fullly qualified nameSystem.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 theMapPath
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.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.
这是一个没有使用正确框架的简单情况,我的意思是完整的胖版本而不是默认的“轻”版本。
右键单击该项目,然后单击“属性”,确保选择最新框架的完整版本,即“.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'
尝试在项目中添加对
System.Web
的引用。HttpContext
是System.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 ofSystem.Web
.http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx