mar*_*arc 4 c# azure azure-cognitive-search asp.net-core azure-search-.net-sdk
使用.NetCore 1.1.2.
通过Azure Search SDK成功获取搜索结果后,我正在尝试解码metadata_storage_path值.我见过有人说要在.NET中使用HttpServerUtility.UrlTokenDecode或者在这里看到其他语言中的等价物.
那么问题就变成了,HttpServerUtility.UrlTokenDecode的.NetCore中的等价物是什么?附:
var pathEncoded = "aHR0cHM6Ly9mYWtlZC5ibG9iLmNvcmUud2luZG93cy5uZXQvcGRmYmxvYnMvYW5udWFsX3JlcG9ydF8yMDA5XzI0NTU20";
Run Code Online (Sandbox Code Playgroud)
我尝试过以下方法:
var pathbytes = Convert.FromBase64String(pathEncoded);
//Throws System.FormatException "Invalid length for a Base-64 char array or string."
Run Code Online (Sandbox Code Playgroud)
和
var pathbytes = WebEncoders.Base64UrlDecode(pathEncoded);
//Throws System.FormatException - "TODO: Malformed input."
Run Code Online (Sandbox Code Playgroud)
有趣的是,如果我切断了pathEncoded中的最后一个字符,一切都运行正常...用Microsoft.AspNetCore 1.1.2处理这种情况的正确方法是什么?
小智 6
我在 asp.net core 2.1 中使用了以下函数来编码来自 Azure 搜索的 meta_storage_path 值。
private string DecodeBase64String(string encodedString)
{
var encodedStringWithoutTrailingCharacter = encodedString.Substring(0, encodedString.Length - 1);
var encodedBytes = Microsoft.AspNetCore.WebUtilities.WebEncoders.Base64UrlDecode(encodedStringWithoutTrailingCharacter);
return HttpUtility.UrlDecode(encodedBytes, Encoding.UTF8);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1160 次 |
| 最近记录: |