作为我们应用程序的一部分,用户可以将一些数据以 XML 形式保存在服务器上,这些数据将成为他们的 RSS 提要。
现在,用户创建的一些文件的文件名中包含 & ,如 BB&T_RSS.xml。
所以当用户将其指向 http://example.com/BB&T.xml 时,他们不会得到这个。
如何阻止这个?我尝试了 BB%26T.xml、BB&T.xml,但在 IE、Chrome 上没有成功
最佳答案
使用
%26
对于
&
http://example.com/BB%26T.xml ,
http://www.w3schools.com/tags/ref_urlencode.asp
然后使用
HttpServerUtility.UrlDecode Method
再次从url获取文件
URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as a question mark (?), ampersand (&), slash mark (/), and spaces might be truncated or corrupted by some browsers. As a result, these characters must be encoded in tags or in query strings where the strings can be re-sent by a browser in a request string.
Many URL schemes reserve certain characters for a special meaning: their appearance in the scheme-specific part of the URL has a designated semantics. If the character corresponding to an octet is reserved in a scheme, the octet must be encoded. The characters ";", "/", "?", ":", "@", "=" and "&" are the characters which may be reserved for special meaning within a scheme. No other characters may be reserved within a scheme. (src)
关于asp.net - RSS Feed URL 中的 & 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4691263/