在C#中System.Web中找不到HttpServerUtility类
问题描述:
我试图在C#中使用Visual Studio 2005调用HttpServerUtuility.URLDecode function,但无法找到它。我是using System.Web
,但是这个班似乎不在那里。我是否需要为我的项目添加某种参考?在C#中System.Web中找不到HttpServerUtility类
答
的几点:
- 您需要的
System.Web
装配 - 你需要获取类名称权(
HttpServerUtility
,不HttpServerUtuility
) - 引用您需要获取的方法名称权(
UrlDecode
,不URLDecode
) - 您需要的类的实例,因为它是一个实例方法
获取实例可能是最难的部分,除非您在ASP.NET中 - 它没有任何公共构造函数或静态属性来获取实例。通常你会使用HttpContext.Server
。另一种方法是使用HttpUtility.UrlDecode
,其中是的一种静态方法。 (同样,你需要System.Web
参考。)
答
添加对System.Web程序集的引用。
答
只好组件添加到我的网页API
System.Web
System.Web.Abstractions
System.Web.ApplicationServices
然后键入HttpServerUtility,按 “CTRL +。”发挥魅力。 – RichardOD 2009-09-02 16:06:49