HttpContext not available in Class Library

廉价感情. 提交于 2019-12-09 02:12:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!