控制台应用程序中的 HttpUtility.UrlEncode

发布于 2024-08-19 04:28:36 字数 490 浏览 3 评论 0 原文

我想在控制台应用程序、VB.NET、VS 2010 Beta 2 中使用 HttpUtility.UrlEncode。

System.Web.HttpUtility.UrlEncode(item)

错误消息:“HttpUtility”不是“Web”的成员。

这个问题 Anjisan建议添加对System.Web的引用,如下:

  1. 在您的解决方案资源管理器中,右键单击引用
  2. 选择“添加引用”
  3. 在“添加引用”对话框中,使用 .NET 选项卡
  4. 向下滚动到 System.Web,选择它,然后单击“确定”

但是,我在该位置没有 System.Web 条目。

I'd like to use HttpUtility.UrlEncode in a console application, VB.NET, VS 2010 Beta 2.

System.Web.HttpUtility.UrlEncode(item)

Error message: 'HttpUtility' is not a member of 'Web'.

In this question Anjisan suggests to add a reference to System.Web, as follows:

  1. In your solution explorer, right click on references
  2. Choose "add reference"
  3. In the "Add Reference" dialog box, use the .NET tab
  4. Scroll down to System.Web, select that, and hit ok

However, I don't have a System.Web entry at that location.

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

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

发布评论

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

评论(7

耳钉梦 2024-08-26 04:28:36

System.Web 在那里,但默认情况下 Visual Studio 似乎不按名称排序。您需要单击组件名称列才能对该列表进行排序。

我能够运行此代码:

Console.WriteLine(System.Web.HttpUtility.UrlEncode(" ")); // +

只需添加 System.Web 引用,没有 System.Web.Extensions

另外,您应该将目标框架从 .NET Framework 4 Client Profile 替换为 .NET Framework 4;转到项目>>属性...>>应用选项卡

System.Web is there, but seems Visual Studio doesn't sort by name by default. You'll need to click Component name column to get that list sorted.

I was able to run this code:

Console.WriteLine(System.Web.HttpUtility.UrlEncode(" ")); // +

Just adding a System.Web reference, without System.Web.Extensions.

Also, You should replace your target framework from .NET Framework 4 Client Profile to .NET Framework 4; go to Project >> Properties... >> Application tab

神也荒唐 2024-08-26 04:28:36

确保您的目标框架是“.NET Framework 4”而不是“.NET Framework 4 Client Profile”。

Make sure your target framework is ".NET Framework 4" not ".NET Framework 4 Client Profile".

半葬歌 2024-08-26 04:28:36

如果您使用的是 .NET 4.0 或更高版本,则可以使用 WebUtility.UrlEncode 与客户端配置文件一起使用(不需要 System.Web 程序集引用)。

If you are using .NET 4.0 or later, you can use WebUtility.UrlEncode which works with client profile (does not require System.Web assembly reference).

白芷 2024-08-26 04:28:36

@iar,框架没有设置为“错误的框架”。在 Visual Studio 2010 中,控制台和 Windows 应用程序(还有更多)默认以 .NET Framework 4 Client Profile 为目标。这是设计使然。当您在“新建项目”对话框中定位“.NET Framework 4”时,就会发生这种情况。为什么它没有找到 System.Web.dll 是因为它不是 .NET Framework 4 Client Profile 的一部分,因此项目系统无法找到它并在构建时发出警告(您可能忽略了该警告,假设您引用了系统.Web.dll)。您也不会在“添加引用”对话框的 .NET 选项卡中找到 System.Web.dll,因为该列表是根据目标框架进行过滤的。

@iar, the framework was not set to "the wrong one". Console and Windows applications (there are more) target .NET Framework 4 Client Profile by default in Visual Studio 2010. This is by design. And it happens when you target ".NET Framework 4" in the New Project Dialog. Why it didn't find System.Web.dll is because it is not part of the .NET Framework 4 Client Profile, so the project system cannot find it and issues a warning during build-time (which you probably ignored, granting you referenced System.Web.dll). You won't find System.Web.dll in the .NET tab in Add Reference dialog also, because that list is filtered according to the targeted framework.

攀登最高峰 2024-08-26 04:28:36

您需要添加对 System.WebSystem.Web.Extensions 的引用。

You need to add a reference to both System.Web and System.Web.Extensions.

不寐倦长更 2024-08-26 04:28:36

将项目的目标框架从“.NET Framework 4 Client Profile”更改为“.NET Framework 4.0”对我很有帮助,使用 .NET Framework 4 Client Profile 作为目标框架,我可以通过浏览到 C:\添加引用窗口中的 WINDOWS\Microsoft.NET\Framework\v2.0.50727 但对 System.Web 4.0 dll 执行相同操作会发出警告。

Changing the project's Target Framework from ".NET Framework 4 Client Profile" to ".NET Framework 4.0" helped me, with .NET Framework 4 Client Profile as Target framework I was able to add System.Web 2.0 version by Browsing to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 from Add reference window but doing the same for System.Web 4.0 dll gave a warning.

被你宠の有点坏 2024-08-26 04:28:36

对于 Visual Studio 2010 中的 VB 项目,将目标框架从“.NET Framework 4.0 Client Profile”更改为“.NET Framework 4.0”的选项位于“Project >”下。属性>编译> “高级编译选项...”

For VB projects in Visual Studio 2010, the option to change the target framework from ".NET Framework 4.0 Client Profile" to ".NET Framework 4.0" is under Project > Properties > Compile > 'Advanced Compile Options...'

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