URL恩code在C#中的所有非字母数字 [英] URL Encode all non alpha numeric in C#

查看:113
本文介绍了URL恩code在C#中的所有非字母数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为C的电子邮件地址完全URL连接$ C $。

I need to fully URL Encode an email address.

HttpUtility.UrlEn code似乎忽略某些字符,如!和

HttpUtility.UrlEncode seems to ignore certain characters such as ! and .

我需要传递一个电子邮件地址,URL中的格式化是这样的:

I need to pass an email address in a url formated like this:

/Users/me@example.com/Comments

由于我的WebMethod URI模板看起来是这样的:

Because my WebMethod uri template looks like this:

[WebGet(UriTemplate = "Users/{emailAddress}/Comments")]

期间打破WCF并不会通过电子邮件地址给我的REST Web服务的方法。 拆除期间传递值就好了。我希望有将连接code中所有非字母数字字符,因为一切消费这项服务将需要做到这一点的方法。

The period breaks WCF and will not pass the email address to my REST webservice method. Removing the period passes the value just fine. I'm hoping there is a method which will encode all non alpha numeric characters since everything consuming this service will need to do this.

修改

我用曾经考虑过:

Convert.ToBase64String(Encoding.ASCII.GetBytes("something+me@example.com"))

大多数其他语言有简单的方法将字符串转换为Base64?我最关心的是我们的客户谁消费这种服务将需要连接code使用Java,PHP和Ruby等的电子邮件地址。

Do most other languages have easy ways to convert a string to base64? My main concern is that our customers who consume this service will need to encode the email address using Java, PHP, Ruby, etc.

推荐答案

我发现了一个解决这个问题。

I've discovered a solution to this issue.

.NET 4.0中实际上已经解决了这一问题,在URI模板特殊字符。

.Net 4.0 has actually fixed the problem with special characters in the URI Template.

这线程我指出了正确的方向。 <一href="http://social.msdn.microsoft.com/Forums/en/dataservices/thread/b5a14fc9-3975-4a7f-bdaa-b97b8f26212b" rel="nofollow">http://social.msdn.microsoft.com/Forums/en/dataservices/thread/b5a14fc9-3975-4a7f-bdaa-b97b8f26212b

This thread pointed me in the right direction. http://social.msdn.microsoft.com/Forums/en/dataservices/thread/b5a14fc9-3975-4a7f-bdaa-b97b8f26212b

我添加了所有的配置设置和它的工作。但是请注意,它仅与.NET 4.0中一个真正的IIS安装工作。我似乎无法得到它与Visual Studio开发IIS工作。

I added all the config settings and it worked. But note, it ONLY works with a REAL IIS setup with .Net 4.0. I can't seem to get it to work with the Visual Studio Dev IIS.

更新 - 其实,我试着删除那些配置设置,它仍然有效。这也许是因为.NET 4.0中已经修复了这个问题,在默认情况下。

Update - Actually, I tried removing those config settings and it still works. It maybe be that .Net 4.0 has fixed this problem by default.

这篇关于URL恩code在C#中的所有非字母数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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