Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpServerUtility.UrlTokenDecode fails "sometimes" (Invalid length for a Base-64 char array.)
    text
    copied!<p>We have an <code>IHttpHandler</code> for stylesheets and add a <code>&lt;link/&gt;</code> tag to the page like this:</p> <pre><code>HtmlGenericControl link = new HtmlGenericControl("link"); link.Attributes.Add("rel", "stylesheet"); link.Attributes.Add("href", "stylesheet.axd?d=" + HttpServerUtility.UrlTokenEncode(token)); head.Controls.Add(link); </code></pre> <p>In the <code>stylesheet.axd</code> handler, we <code>UrlTokenDecode</code> the <code>d</code> query string parameter like this:</p> <pre><code>var token = HttpServerUtility.UrlTokenDecode(Request.QueryString["d"]); </code></pre> <p>This works most of the time but every now and then we find one of the following two exceptions in our log:</p> <pre><code>[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) ... </code></pre> <p>Any ideas what would cause this phenomenon?</p> <p>Remarks:</p> <ul> <li>the resulting URL is &lt; 1500, so below any known URL limits (e.g. IE: 2083)</li> <li>seems to be independent of user agent (we have these exceptions for IE6,7,8, FF &amp; Chrome)</li> <li>our (unconfirmed) suspicions include AntiVirus products, HTTP proxies, browser addons</li> <li>found <a href="https://stackoverflow.com/questions/858761/what-causing-this-invalid-length-for-a-base-64-char-array">this</a> remotely related question, but it's about a viewstate issue</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload