在我的应用程序中,我想添加这样的排序:' https://example.com/entity?sort_by=+property '.
当我尝试将加号传递给查询时,ASP.NET Core 返回没有加号的“属性”。 我该如何解决这个问题?
最佳答案
根据RFC3986,加号是保留字符这是 URI 的标准规范,它用于表示空格,因此,如果您想在 URL 中将它用作字面上的“+”字符而不是空格,则需要对其进行编码,使其看起来像:
https://example.com/entity?sort_by=%2Bproperty
在 ASP.NET Core 中,您可以按如下方式编码/解码 URL:
using System.Net;
string url = "https://example.com/entity?sort_by=+property";
string encodedUrl = WebUtility.UrlEncode(url);
string decodedUrl = WebUtility.UrlEncode(encodedUrl);
参见 here有关 URL 编码的更多信息。
关于c# - 加号登录查询参数变为空字符串(ASP.NET Core),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57934861/