问题
I seem to be having an issue with the HttpServerUtility.UrlTokenDecode(string)
, as it is constantly returning null, causing the program to crash.
From what I have gathered, this method will convert a string to it's base64 Byte-Array. Unfortunately, the original developer of the code is no longer with us, and it seems not many people in my office are familiar with the code.
public string DecodeUrlData(string urlData)
{
string lsReturnVal = string.Empty;
byte[] decodedrtfBytes = HttpServerUtility.UrlTokenDecode(urlData);
lsReturnVal = System.Text.ASCIIEncoding.ASCII.GetString(decodedrtfBytes);
return lsReturnVal;
}
That is the code that has been written, and urlData
has the following value:
urlData = "pdfSignature template testing."
(It should also be known that urlData
may have either a "string" value, or a rtfformatted string)
But what ends up happening is when the HttpServerUtility.UrlTokenDecode(urlData)
line is executed, the byte array ends up being null (causing an exception in the following line).
Is there another way to convert the string to base64 that would work, or why does it keep producing a null value?
回答1:
According to the HttpServerUtility.UrlTokenDecode documentation, the input
parameter should be a Url token previously encoded via UrlTokenEncode
.
Quote:
The UrlTokenDecode method converts a URL string token, which encodes binary data as base 64 digits, to its equivalent byte array representation. Use the UrlTokenDecode method to decode tokens transmitted on the URL and encoded by using the UrlTokenEncode.
来源:https://stackoverflow.com/questions/6523194/httpserverutility-urltokendecode-only-seems-to-return-null