本文介绍了如何解码.NET Core中由Azure搜索索引器生成的meta_storage_path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用.NetCore 1.1.2.

Using .NetCore 1.1.2.

在成功通过Azure搜索SDK获得搜索结果之后,我尝试对metadata_storage_path值进行解码.我见过有人说要在.NET中使用HttpServerUtility.UrlTokenDecode或其他语言的等效版本在此处看到.

After successfully getting results from a search via Azure Search SDK, I am trying to decode the metadata_storage_path value. I've seen people saying to use HttpServerUtility.UrlTokenDecode in .NET or an equivalent in other languages as seen here.

然后问题就变成了,HttpServerUtility.UrlTokenDecode的.NetCore中有什么等效项?使用:

Then the question becomes, what is the equivalent in .NetCore of HttpServerUtility.UrlTokenDecode? With:

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处理这种情况的正确方法是什么?

Interestingly enough, everything works just fine if I cut off the last charater in pathEncoded... What is the proper way to handle this situation with Microsoft.AspNetCore 1.1.2?

推荐答案

HttpServerUtility.UrlTokenEncode将附加的尾随字符附加到编码的字符串.您做对了-只需删除该多余的字符并使用WebEncoders.Base64UrlDecode.有关详细信息,请参见此问题与解答.

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.

这篇关于如何解码.NET Core中由Azure搜索索引器生成的meta_storage_path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 22:32