In my application I want to add sorting like that: 'https://example.com/entity?sort_by=+property'.
When I try to pass plus sign to query, ASP.NET Core returns 'property' without plus sign. How can I fix this?
In my application I want to add sorting like that: 'https://example.com/entity?sort_by=+property'.
When I try to pass plus sign to query, ASP.NET Core returns 'property' without plus sign. How can I fix this?
The plus symbol is a reserved character according to RFC3986 which is the standard specification for URIs and it is used to represent a space, therefore, if you want to use it in your URL as literally the "+" character instead of a space, you need to encode it so it looks like:
https://example.com/entity?sort_by=%2Bproperty
In ASP.NET Core you can encode / decode URL's as follows:
using System.Net;
string url = "https://example.com/entity?sort_by=+property";
string encodedUrl = WebUtility.UrlEncode(url);
string decodedUrl = WebUtility.UrlDecode(encodedUrl);
See here for more info about URL encoding.
+to mean" ", then you should encode your string.