URL Encode and Decode in ASP.NET Core

For ASP.NET Core 2.0+ just add System.Net namespace – WebUtility class is shipped as part of System.Runtime.Extensions nuget package, that is referenced by default in ASP.NET Core project. For the previous version add Microsoft.AspNetCore.WebUtilities nuget package. Then the WebUtility class will be available for you: public static class WebUtility { public static string UrlDecode(string encodedValue); … Read more

Server.UrlEncode vs. HttpUtility.UrlEncode

I had significant headaches with these methods before, I recommend you avoid any variant of UrlEncode, and instead use Uri.EscapeDataString – at least that one has a comprehensible behavior. Let’s see… HttpUtility.UrlEncode(” “) == “+” //breaks ASP.NET when used in paths, non- //standard, undocumented. Uri.EscapeUriString(“a?b=e”) == “a?b=e” // makes sense, but rarely what you // … Read more

URLEncoder not able to translate space character

This behaves as expected. The URLEncoder implements the HTML Specifications for how to encode URLs in HTML forms. From the javadocs: This class contains static methods for converting a String to the application/x-www-form-urlencoded MIME format. and from the HTML Specification: application/x-www-form-urlencoded Forms submitted with this content type must be encoded as follows: Control names and … Read more

URL encode sees “&” (ampersand) as “&” HTML entity

Without seeing your code, it’s hard to answer other than a stab in the dark. I would guess that the string you’re passing to encodeURIComponent(), which is the correct method to use, is coming from the result of accessing the innerHTML property. The solution is to get the innerText/textContent property value instead: var str, el … Read more

How do you UrlEncode without using System.Web?

System.Uri.EscapeUriString() can be problematic with certain characters, for me it was a number / pound ‘#’ sign in the string. If that is an issue for you, try: System.Uri.EscapeDataString() //Works excellent with individual values Here is a SO question answer that explains the difference: What’s the difference between EscapeUriString and EscapeDataString? and recommends to use … Read more

URL encoding in Android

You don’t encode the entire URL, only parts of it that come from “unreliable sources”. Java: String query = URLEncoder.encode(“apples oranges”, “utf-8”); String url = “http://stackoverflow.com/search?q=” + query; Kotlin: val query: String = URLEncoder.encode(“apples oranges”, “utf-8”) val url = “http://stackoverflow.com/search?q=$query” Alternatively, you can use Strings.urlEncode(String str) of DroidParts that doesn’t throw checked exceptions. Or use … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)