c# - Server.UrlEncode(string s)... 没有

标签 c# .net javascript

Server.UrlEncode("My File.doc") 返回"My+File.doc",而javascript escape("My File.doc") 返回"My%20File.doc"。据我了解,javascript 是 corectly URL 编码字符串,而 .net 方法不是。在练习放置 http://somesite/My+File.doc 时,它似乎确实是这样工作的在我可以使用 firefox/即测试的任何情况下都不会获取“我的 File.doc”和 IIS,而 http://somesite/My%20File.doc工作良好。我是不是遗漏了什么或者 Server.UrlEncode 是否无法正常工作?

最佳答案

使用 Javascripts encodeURIComponent()/decodeURIComponent() 用于使用 .Net 的 URLEncode/URLDecode 进行“往返”编码。

编辑

据我所知,历史上“+”在 URL 编码中用作空格字符 (ASCII 20) 的特殊替代。如果实现不将空格视为具有“+”替换的特殊字符,那么它仍然必须使用其 ASCII 代码(因此为“%20”)对其进行转义。

http://bytes.com/topic/php/answers/5624-urlencode-vs-rawurlencode 上对情况进行了非常好的讨论。 .顺便说一句,这是不确定的。 RFC 2396 将空格与其他字符混为一谈,没有未保留的表示形式,这与“%20”人群有关。

RFC 1630 支持“+”人群(通过论坛讨论)...

Within the query string, the plus sign is reserved as shorthand notation for a space. Therefore, real plus signs must beencoded. This method was used to make query URIs easier to pass in systems which did not allow spaces.

此外,核心 RFC 是...

RFC 1630 - WWW 中的通用资源标识符

RFC 1738 - 统一资源定位符 (URL)

RFC 2396 - 统一资源标识符 (URI):通用语法

关于c# - Server.UrlEncode(string s)... 没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2516266/

相关文章:

Google 的 'Encoded Polyline Algorithm' 的 C# 实现

c# - 我应该如何从一个 Controller 操作返回两个对象列表?

c# - 使用 C# 创建带有嵌入式 SWF 和 FlashVars 的 PDF

c# - 通用类派生约束的首选语法是什么?

javascript - NodeJs-事件循环只处理 I/O 请求吗?

c# - .Net (C#) Enum 重写为 java

c# - StaticResource 标记扩展与 System.Windows.Application.FindResource

c# - 将常量从 vb 转换为 c#

javascript - D3 中的鼠标位置

javascript - 如何对<select>中动态生成的<option>进行排序