HttpServerUtility.UrlTokenDe code未能"有时" (无效的长度为Base-64字符数组)。 [英] HttpServerUtility.UrlTokenDecode fails "sometimes" (Invalid length for a Base-64 char array.)

查看:247
本文介绍了HttpServerUtility.UrlTokenDe code未能"有时" (无效的长度为Base-64字符数组)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个的IHttpHandler 的样式表,并添加<链接/> 标签来像这样的页面

We have an IHttpHandler for stylesheets and add a <link/> tag to the page like this:

HtmlGenericControl link = new HtmlGenericControl("link");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("href", "stylesheet.axd?d=" +
                                    HttpServerUtility.UrlTokenEncode(token));
head.Controls.Add(link);

stylesheet.axd 处理程序,我们 UrlTokenDe code D 查询字符串参数是这样的:

In the stylesheet.axd handler, we UrlTokenDecode the d query string parameter like this:

var token = HttpServerUtility.UrlTokenDecode(Request.QueryString["d"]);

这工作的大部分时间,但每一个现在,然后我们发现在我们的日志中的以下两个例外之一:

This works most of the time but every now and then we find one of the following two exceptions in our log:

[FormatException: Invalid character in a Base-64 string.]
   System.Convert.FromBase64CharArray(Char[] inArray, Int32 offset, Int32 length)
   System.Web.HttpServerUtility.UrlTokenDecode(String input)
   ...

[FormatException: Invalid length for a Base-64 char array.]
   System.Convert.FromBase64CharArray(Char[] inArray, Int32 offset, Int32 length)
   System.Web.HttpServerUtility.UrlTokenDecode(String input)
   System.Web.HttpServerUtilityWrapper.UrlTokenDecode(String input)
   ...

任何想法会造成这种现象呢?

Any ideas what would cause this phenomenon?

注:


  • 产生的URL为&lt; 1500年,所以下面任何已知URL限制(例如IE:2083)

  • 似乎是独立的用户代理(我们有这些例外IE6,7,8,FF&安培;镀铬)

  • 我们的(未经证实)怀疑包括防病毒产品,HTTP代理服务器,浏览器插件

  • 找到<一href=\"http://stackoverflow.com/questions/858761/what-causing-this-invalid-length-for-a-base-64-char-array\">this远程相关的问题,但它是关于一个视图状态的问题

  • the resulting URL is < 1500, so below any known URL limits (e.g. IE: 2083)
  • seems to be independent of user agent (we have these exceptions for IE6,7,8, FF & Chrome)
  • our (unconfirmed) suspicions include AntiVirus products, HTTP proxies, browser addons
  • found this remotely related question, but it's about a viewstate issue

推荐答案

我们也有类似的问题,所以我们避免了UrlTokenEn code,原因是有时的base64尾随垫字符'=='等等,所以他们不得到的网址正确传输。而且我认为这是在.NET中的一个错误,但我们把它改成以下,并开始工作。

We had similar problems, so we avoided UrlTokenEncode, the reason is base64 sometimes pads trailing characters as '==' and so on, so they dont get transmitted in url correctly. And I think there is a bug in .NET, however we changed it to following and it started working.

我们做了这样的,它总是工作。

We did this way and it worked always.

url += "&d=" + HttpServerUtility.UrlEncode( Convert.ToBase64String( ... ))

只有

和接收侧,我们使用

and at receiving side, we use only

data = Convert.FromBase64String( Request.QueryString["d"] )

我们并不需要使用UrlDe code,因为查询字符串对象在去codeD格式存储的信息了。

We do not need to use UrlDecode, because the query string object stores information in decoded format already.

这篇关于HttpServerUtility.UrlTokenDe code未能&QUOT;有时&QUOT; (无效的长度为Base-64字符数组)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆