简体   繁体   English

Server.UrlEncode&Server.UrlDecode

[英]Server.UrlEncode & Server.UrlDecode

I don't know, Why do we use Server.UrlEncode() & Server.UrlDecode() ?! 我不知道,为什么我们使用Server.UrlEncode()Server.UrlDecode() in QueryString we see anything in URL, so why do we want encode or decode them? 在QueryString中我们看到URL中的任何内容,那么我们为什么要编码或解码呢?

The URLEncode method applies URL encoding rules, including escape characters, to a specified string. URLEncode方法将URL编码规则(包括转义字符)应用于指定的字符串。

URLEncode converts characters as follows: URLEncode转换字符如下:

Spaces ( ) are converted to plus signs (+). Spaces()转换为加号(+)。

Non-alphanumeric characters are escaped to their hexadecimal representation. 非字母数字字符转义为十六进制表示。

Also, I think you are talking about HttpServerUtility.UrlDecode method which decodes the encoded string and returnes you back the original string. 此外,我认为你在谈论HttpServerUtility.UrlDecode方法,它解码编码的字符串并返回原始字符串。

URL-decodes a string and returns the decoded string URL解码字符串并返回解码后的字符串

URL encoding ensures that all browsers will correctly transmit text in URL strings. URL编码可确保所有浏览器都能正确传输URL字符串中的文本。 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. 因此,这些字符必须在标记或查询字符串中进行编码,其中字符串可以由浏览器在请求字符串中重新发送。

UrlDecode is a convenient way to access the HttpUtility.UrlDecode method at run time from an ASP.NET application. UrlDecode是一种在ASP.NET应用程序中运行时访问HttpUtility.UrlDecode方法的便捷方法。 Internally, UrlDecode uses HttpUtility.UrlDecode to decode strings. 在内部,UrlDecode使用HttpUtility.UrlDecode来解码字符串。

More info ... 更多信息 ...

Server.URLEncode Server.URLEncode

HttpServerUtility.UrlDecode HttpServerUtility.UrlDecode

It is taken from here 它取自这里

URLEncode converts characters as follows: URLEncode转换字符如下:

 Spaces ( ) are converted to plus signs (+). Non-alphanumeric characters are escaped to their hexadecimal representation. 
<%Response.Write(Server.URLEncode("http://www.microsoft.com")) %> 

produces the following output:

http%3A%2F%2Fwww%2Emicrosoft%2Ecom  

Some characters are not legal in URLs, so they must be encoded. 某些字符在URL中不合法,因此必须对它们进行编码。 This was the first hit I found for a list of illegal characters. 是我发现的第一个非法字符列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM