How to decode metadata_storage_path produced by Azure Search indexer in .NET Core

不羁岁月 提交于 2019-12-01 06:44:19

HttpServerUtility.UrlTokenEncode appends an extra trailing character to the encoded string. You're doing it right - just remove that extra character and use WebEncoders.Base64UrlDecode. See this Q&A for details.

I used the following function in asp.net core 2.1 to encode the meta_storage_path value from Azure search.

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);
}

I just wanted to add that you can also deselect the 'Base-64 Encode Keys' Azure search indexer option.

NOTE: Only do this for fields with no characters Azure considers invalid for document keys.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!