c# - 服务器.UrlEncode & 服务器.UrlDecode

标签 c# asp.net

我不知道,为什么我们要使用 Server.UrlEncode() & Server.UrlDecode()?! 在 QueryString 中我们看到 URL 中的任何内容,那么为什么我们要对它们进行编码或解码?

最佳答案

The URLEncode method applies URL encoding rules, including escape characters, to a specified string.

URLEncode converts characters as follows:

Spaces ( ) are converted to plus signs (+).

Non-alphanumeric characters are escaped to their hexadecimal representation.

此外,我认为您在谈论 HttpServerUtility.UrlDecode 方法,该方法解码编码字符串并返回原始字符串。

URL-decodes a string and returns the decoded string

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.

UrlDecode is a convenient way to access the HttpUtility.UrlDecode method at run time from an ASP.NET application. Internally, UrlDecode uses HttpUtility.UrlDecode to decode strings.

更多信息...

Server.URLEncode

HttpServerUtility.UrlDecode

关于c# - 服务器.UrlEncode & 服务器.UrlDecode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10654057/

相关文章:

asp.net - System.Diagnostics.Process.Start 无法从 IIS 运行

asp.net - jquery ajax调用后如何重新加载asp.net GridView?

c# - 将 float 显示到文本框类型 "number"

c# - TabControl WPF 中的延迟加载数据绑定(bind)列表

c# - 将新测试项目的测试引入解决方案时,MSTest 单元测试适配器无法连接到数据源

asp.net - 如何删除身份验证 Cookie

c# - 如何在 ASP.NET 应用程序中使用 SSL

c# - 桌面应用程序可能的数据访问层设计模式是什么?

c# - 将 DateTime 存储到 cookie 中的最佳方法是什么?

c# - Membership.GetUser() 在应用程序启动时返回 null