【问题标题】:HttpServerUtility.UrlTokenDecode only seems to return nullHttpServerUtility.UrlTokenDecode 似乎只返回 null
【发布时间】:2013-04-28 20:21:39
【问题描述】:

HttpServerUtility.UrlTokenDecode(string) 似乎有问题,因为它不断返回 null,导致程序崩溃。

根据我收集到的信息,此方法会将字符串转换为 base64 字节数组。不幸的是,代码的原始开发人员已经不在我们身边,而且我办公室里似乎没有多少人熟悉代码。

public string DecodeUrlData(string urlData)
{
    string lsReturnVal = string.Empty;
    byte[] decodedrtfBytes = HttpServerUtility.UrlTokenDecode(urlData);

    lsReturnVal = System.Text.ASCIIEncoding.ASCII.GetString(decodedrtfBytes);
    return lsReturnVal;
}

也就是已经写好的代码,urlData的值如下:

urlData = "pdfSignature template testing."

(还应该知道urlData可能有一个“字符串”值,也可能是一个rtf格式的字符串)

但最终发生的是当HttpServerUtility.UrlTokenDecode(urlData) 行执行时,字节数组最终为空(导致下一行出现异常)。

是否有另一种方法可以将字符串转换为 base64,或者为什么它会不断产生空值?

【问题讨论】:

  • urlData 值是以前通过UrlTokenEncode 编码的令牌还是纯文本字符串?
  • 我相信它只是纯文本字符串。

标签: c# null base64 httpserverutility


【解决方案1】:

根据HttpServerUtility.UrlTokenDecode documentationinput 参数应该是之前通过UrlTokenEncode 编码的Url token

引用:

UrlTokenDecode 方法将一个 URL 字符串标记,对二进制进行编码 以 64 位为基数的数据,对其 等效字节数组表示。 使用 UrlTokenDecode 方法 解码在 URL 上传输的令牌 并通过使用编码 UrlTokenEncode.

【讨论】:

  • 哇,我不知道我是怎么错过最后一点的。该页面是我检查的第一件事。我想我只需要多加注意。
猜你喜欢
  • 1970-01-01
  • 2015-09-17
  • 2012-09-07
  • 2021-08-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-26
  • 1970-01-01
  • 2020-07-12
相关资源
最近更新 更多