Can't find HttpServerUtility class in System.Web in C#

你离开我真会死。 提交于 2019-12-23 08:05:34

问题


I'm trying to call the HttpServerUtuility.URLDecode function in C# using Visual Studio 2005, but it can't be found. I'm using System.Web properly, but the class doesn't seem to be there. Do I need to add some sort of reference to my project?


回答1:


A few points:

  • You need a reference to the System.Web assembly
  • You need to get the class name right (HttpServerUtility, not HttpServerUtuility)
  • You need to get the method name right (UrlDecode, not URLDecode)
  • You need an instance of the class, as it's an instance method

Getting an instance is likely to be the hardest part, unless you're in ASP.NET - it doesn't have any public constructors or a static property to fetch an instance. Usually you'd use HttpContext.Server. An alternative is to use HttpUtility.UrlDecode, which is a static method. (Again, you'll need a reference to System.Web.)




回答2:


Add a reference to the System.Web assembly.




回答3:


Had to add assemblies to my web api

System.Web
System.Web.Abstractions
System.Web.ApplicationServices


来源:https://stackoverflow.com/questions/1368596/cant-find-httpserverutility-class-in-system-web-in-c-sharp

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