Uri.EscapeDataString or HttpUtility.UrlEncode is the correct way to escape a string meant to be part of a URL.

Take for example the string "Stack Overflow":

  • HttpUtility.UrlEncode("Stack Overflow") --> "Stack+Overflow"

  • Uri.EscapeUriString("Stack Overflow") --> "Stack%20Overflow"

  • Uri.EscapeDataString("Stack + Overflow") --> Also encodes "+" to "%2b" ---->Stack%20%2B%20%20Overflow

Only the last is correct when used as an actual part of the URL (as opposed to the value of one of the query string parameters)

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2021-04-10
  • 2022-01-09
  • 2022-12-23
  • 2021-12-28
  • 2021-09-15
猜你喜欢
  • 2022-02-06
  • 2022-01-24
  • 2021-10-02
  • 2021-10-03
  • 2021-10-10
  • 2022-12-23
  • 2021-04-10
相关资源
相似解决方案