在C#中的System.Web中找不到HttpServerUtility类

Eli*_*ght 7 c# urldecode httpserverutility

我正在尝试使用Visual Studio 2005在C#中调用HttpServerUtuility.URLDecode函数,但无法找到它.我using System.Web很好,但是班级似乎并不存在.我是否需要为我的项目添加某种引用?

Jon*_*eet 14

几点:

  • 您需要对System.Web程序集的引用
  • 你需要让类名正确(HttpServerUtility不是HttpServerUtuility)
  • 你需要正确的方法名称(UrlDecode,不是URLDecode)
  • 你需要一个类的实例,因为它是一个实例方法

获取实例可能是最难的部分,除非您在ASP.NET中 - 它没有任何公共构造函数或静态属性来获取实例.通常你会用HttpContext.Server.另一种方法是使用HttpUtility.UrlDecode,这一种静态方法.(再次,你需要一个参考System.Web.)


Arm*_*rat 5

添加对System.Web程序集的引用.