WebHelper.cs 840 B

1234567891011121314151617181920212223242526272829
  1. using System.Web;
  2. namespace FNZCM.Shared.Helpers
  3. {
  4. public static class WebHelper
  5. {
  6. public static string UrlEscape(this string input)
  7. {
  8. if (input == null) return null;
  9. var uri = new Uri(input, UriKind.RelativeOrAbsolute);
  10. if (!uri.IsAbsoluteUri)
  11. {
  12. return input
  13. .Replace("[", "%5B")
  14. .Replace("]", "%5D")
  15. .Replace("'", "%27")
  16. .Replace(" ", "%20")
  17. .Replace("#", "%23")
  18. ;
  19. }
  20. var local = string.Join("/", uri.LocalPath.Split("/").Select(HttpUtility.UrlEncode));
  21. var str = $"{uri.Scheme}://{uri.Authority}{local}";
  22. return str.Replace("+", "%20");
  23. }
  24. }
  25. }