Windows Phone 7 中的 HttpUtility.UrlEncode? [英] HttpUtility.UrlEncode in Windows Phone 7?

查看:15
本文介绍了Windows Phone 7 中的 HttpUtility.UrlEncode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

常规 .Net 框架在 System.Web 程序集中包含 HttpUtility.UrlEncode,而在 Silverlight 中,它似乎已移至 System.Windows.Browser.但是在 Windows Phone 7(我认为它与 Silverlight 相同)中,我似乎无法找到对任何内容进行 UrlEncode 的正确方法.前面提到的程序集在 Windows Phone 7 环境中均不可用.

The regular .Net framework contains HttpUtility.UrlEncode in the System.Web Assembly and in Silverlight it appears it was moved to System.Windows.Browser. But in Windows Phone 7 (which I thought was the same as Silverlight) I can't seem to find a proper way to UrlEncode anything. Neither of the previously mentioned assemblies are available in the Windows Phone 7 environment.

推荐答案

Silverlight 有 Uri.EscapeUriStringUri.EscapeDataString 可用于对 URI 的部分(例如查询字符串和路径组件等)进行 URL 编码.

Silverlight has the Uri.EscapeUriString and Uri.EscapeDataString which can be used to URL-encode portions of a URI such as query strings and path components and such.

即使在桌面框架中,您也不应该仅仅为了 HttpUtility 而依赖 System.Web.dll,尽管许多开发人员仍然这样做.这很糟糕,原因有 3 个.

Even in the desktop framework, you should never take a dependency on System.Web.dll just for HttpUtility, although many developers still do it. This is bad for 3 reasons.

  • 程序集非常大,加载它会显着延迟您的应用程序.
  • 大约 20 行代码将使流程的工作集变得臃肿.
  • 它使您的应用程序需要完整的框架,因为 System.Web 不在客户端配置文件中.

除了上面描述的 Uri 转义方法,如果你需要 HtmlEncode,我只会把代码从 别人写的并将其放入您的应用程序中.

In addition to the Uri escaping methods described above, if you need HtmlEncode, I would just rip code off that someone else wrote and drop it in your application.

这篇关于Windows Phone 7 中的 HttpUtility.UrlEncode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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