使用.NetCore 1.1.2。
在通过Azure成功地从搜索中获得结果之后,我正在尝试解码metadata_storage_path值。我见过有人说在.NET中使用.NET,或者在其他语言中使用如图所示。
那么问题就变成了,在.NetCore of HttpServerUtility.UrlTokenDecode中,什么是等价的?通过以下方式:
var pathEncoded = "aHR0cHM6Ly9mYWtlZC5ibG9iLmNvcmUud2luZG93cy5uZXQvcGRmYmxvYnMvYW5udWFsX3JlcG9ydF8yMDA5XzI0NTU20";
我尝试了以下几点:
var pathbytes = Convert.FromBase64String(pathEncoded);
//Throws System.FormatException "Invalid length for a Base-64 char array or string."
和
var pathbytes = WebEncoders.Base64UrlDecode(pathEncoded);
//Throws System.FormatException - "TODO: Malformed input."
有趣的是,如果我剪掉pathEncoded的最后一个字符,一切都会很好.使用Microsoft.AspNetCore 1.1.2处理这种情况的正确方法是什么?
发布于 2017-06-02 23:37:29
HttpServerUtility.UrlTokenEncode
将额外的尾随字符附加到编码的字符串中。你这样做是对的-只要删除额外的字符,并使用WebEncoders.Base64UrlDecode
。详情请参见这个问答。
发布于 2018-10-05 12:21:24
我在asp.net核心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);
}
发布于 2019-03-01 21:19:04
我只是想补充一下,你也可以取消选择‘Bas-64编码键’Azure搜索索引器选项。
注意:只对没有字符Azure的字段执行此操作,文档键认为无效。
https://stackoverflow.com/questions/44338134
复制相似问题