Cannot find HttpContext in .NET 3.5 and Visual Studio 2008

I used the code here and I get the following error: You cannot use HttpContext.Current.Server.MapPath()

In Visual Studio 2008, ConvertMenuEntry "Solve" will help you when you have no links?

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

How to do it?

How do you usually react in this situation? What are you looking for at msdn.com?

+6
source share
5 answers

What would I do in this situation, look at MSDN (or Google) on the HttpContext . I did this and he talks about it in System.Web . So make sure your project has a link to System.Web .

Add link

System.web

... and then it works:

HttpContext is now available.

+18
source

You can find the documentation for the HttpContext class and it tells you that it is in the System.Web , in System.Web.dll .

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

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

In addition, MapPath only works if you are actually in a web application that has an HTTP context.

+2
source

Timvy has this right, but for completeness. No, VS does not have the built-in "Allow" feature, however this functionality has been partially added by some add-ons. For example, Resharper will add a parameter to add a link and use it when necessary, but it had to be referenced earlier in the solution so that it would not solve the problem with the initial find.

+1
source

This was a simple case of not using the correct structure, and I mean the full version of fat, and not the standard "light" version.

Right-click on the project and then on the properties and make sure that the full version of the latest framework is selected, that is, ".NET Framework 4" and not ".NET Framework 4 Client Profile"

+1
source

Try adding a link in System.Web to your project.

HttpContext is a member of System.Web .

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

0
source

All Articles