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

发布于 2024-08-04 05:26:52 字数 236 浏览 4 评论 0原文

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清眉祭 2024-08-11 05:26:52

几点:

  • 您需要对 System.Web 程序集的引用
  • 您需要正确获取类名(HttpServerUtility,而不是 HttpServerUtility
  • 您需要获得正确的方法名称(UrlDecode,而不是 URLDecode
  • 您需要类的实例,因为它是实例方法

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

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.)

无名指的心愿 2024-08-11 05:26:52

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

Add a reference to the System.Web assembly.

倾城月光淡如水﹏ 2024-08-11 05:26:52

必须将程序集添加到我的 Web api

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

Had to add assemblies to my web api

System.Web
System.Web.Abstractions
System.Web.ApplicationServices
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文