为什么我不能找到或使用UrlEn code在Visual Studio 2010? [英] Why can't I find or use UrlEncode in Visual Studio 2010?

查看:226
本文介绍了为什么我不能找到或使用UrlEn code在Visual Studio 2010?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个,我想EN code为标准的URL格式字符串。从我发现,我应该可以通过 httpUtility.urlEn code 的方法来做到这一点,但我似乎没有有提供。

I have a string that I'd like to encode into the standard URL format. From what I've found, I should be able to do this via the httpUtility.urlEncode method, but I don't seem to have that available.

我添加了使用引用了的System.Web System.Net 无济于事。我也看到其他引用server.urlEn code除其他变种,但我没有看到任何地方的方法。

I've added "using" references to both System.Web and System.Net to no avail. I've also seen other references to server.urlEncode amongst other variants, but I don't see the method anywhere.

我使用C#在Visual Studio 2010的最新版本被称为东西在这个版本不同的方法,藏在别的地方,还是我完全关闭基地?

I'm using the latest version of C# in Visual Studio 2010. Is the method called something different in this version, hidden somewhere else, or am I completely off base?

推荐答案

在默认情况下,在Visual Studio 2010中面向.NET Framework 4.0的客户端配置文件,其中不包括<$ C新项目$ C>的System.Web 组件。

By default, new projects in Visual Studio 2010 target the .NET Framework 4.0 Client Profile, which does not include the System.Web assembly.

您可以修改框架您的项目目标的版本,在项目的属性。在应用程序选项卡,从标有目标框架组合框中选择.NET框架4.0。

You can change the version of the Framework that your project targets in your project's Properties. Under the "Application" tab, select ".NET Framework 4.0" from the combobox labeled "Target framework".

然后,请确保您已添加的引用,的System.Web 使用添加引用对话框。

Then, make sure that you have added a reference to System.Web using the "Add Reference" dialog.

最后,添加使用指令 一>到类的的System.Web 命名空间的顶部:

Finally, add a using directive to the top of your class for the System.Web namespace:

using System.Web;


你会找到 UrlEn code HttpUtility 类方法。样品code:


You'll find the various overloads of the UrlEncode method in the HttpUtility class. Sample code:

HttpUtility.UrlEncode("http://www.google.com/");

这篇关于为什么我不能找到或使用UrlEn code在Visual Studio 2010?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆