问题
I am working on a project where I have a C# class library which needs to use the System.web.HttpContext
. I've done this before in another project without problem but now its not working. I'm not sure what I am missing they're both targeting .net 3.5 and I've added the reference System.web
and added the directive using System.web
.
However, when I try and do HttpContext
nothing is found. I've tried using the full path System.web.HttpContext
but the only thing that comes up are 3 items related to ASP.
Below are screenshots from the working project intellisense and the non-working intellisense
Below is the working screenshot
and below is the non working screenshot
Thanks for any help you can provide
回答1:
This means that either you are using a Client Profile as the Target Framework or the reference to System.Web was not added correctly.
回答2:
Despite your comment that you've added reference to System.Web to the project it is still most likely reason of what you are seeing.
The classes you see are coming from System.Dll, not System.Web.Dll.
回答3:
Just to add some input incase someone else gets hung up on this. If you are in a Unit test project or a Class Library that links back to an MVC project, you may have references to System.Web.Mvc. This DOES NOT INCLUDE System.Web. You must add both if you need something Mvc specific (like a SelectList) AND HttpContext
来源:https://stackoverflow.com/questions/14149815/httpcontext-not-available-in-class-library