1234567891011121314151617181920212223242526272829 |
- using System.Web;
- namespace FNZCM.Shared.Helpers
- {
- public static class WebHelper
- {
- public static string UrlEscape(this string input)
- {
- if (input == null) return null;
- var uri = new Uri(input, UriKind.RelativeOrAbsolute);
- if (!uri.IsAbsoluteUri)
- {
- return input
- .Replace("[", "%5B")
- .Replace("]", "%5D")
- .Replace("'", "%27")
- .Replace(" ", "%20")
- .Replace("#", "%23")
- ;
- }
- var local = string.Join("/", uri.LocalPath.Split("/").Select(HttpUtility.UrlEncode));
- var str = $"{uri.Scheme}://{uri.Authority}{local}";
- return str.Replace("+", "%20");
- }
- }
- }
|