Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

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

Using .NetCore 1.1.2.

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.

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

var pathEncoded = "aHR0cHM6Ly9mYWtlZC5ibG9iLmNvcmUud2luZG93cy5uZXQvcGRmYmxvYnMvYW5udWFsX3JlcG9ydF8yMDA5XzI0NTU20";

I have tried the following:

var pathbytes = Convert.FromBase64String(pathEncoded); 
//Throws System.FormatException "Invalid length for a Base-64 char array or string."

and

var pathbytes = WebEncoders.Base64UrlDecode(pathEncoded);
//Throws System.FormatException - "TODO: Malformed input."

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...