Getting Right Encoding From HTTPContext

- 1 answer

I am trying to build site titles generated dynamically from HTTPContext , but I saw that I have problems when url contains special characters like ß which results in titles having wrong characters for instance fußball translates into fu%C3%9Fball. Right now I store my title in array like that:

string[] customSEOTitle = HttpContext.Current.Request.Url.AbsolutePath
   .Where(s => !string.IsNullOrWhiteSpace(s))
   .Select(s => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s))

The thing is that AbsolutePath returns fu%C3%9Fball when the url is actually fußball. I saw that RawUrl gets right characters , but it does take query string also which I don't want.Is there any generic and straightforward way to do this or I have to write extension method striping query string?



What you might be looking are UrlEncode and UrlDecode methods.

MSDN | HttpServerUtility.UrlDecode Method (String)

Not sure which .NET version you use, see elaborate discussion here.

Replacement for System.Web.HttpUtility.UrlEncode/UrlDecode ASP.NET 5