ASP.NET Invalid character in a Base-64 string

2019-03-31 04:06发布

I recently implemented ELMAH on my site and I have noticed that we frequently get the "Invalid character in a Base-64 string" error. I have never triggered it myself and none of our users have complained about it so I don't know what is going on. From the little I was able to find about it it seems like the viewstate might be getting too big or becoming corrupted or something. Does anybody know what causes this and how to prevent it? Here are what I believe are the pertinent lines in the YSOD.

[FormatException: Invalid character in a Base-64 string.]
[ViewStateException: Invalid viewstate. 
[HttpException (0x80004005): The client disconnected.]

Is there anything I can do about these errors or should I just filter them in ELMAH?

2条回答
劫难
2楼-- · 2019-03-31 04:46

It might be how things are configured. Take a look at this:

http://groups.google.com/group/elmah/browse_thread/thread/ec9c4bffffdaa1a9e/9108b48d3def87db?lnk=gst&q=viewstate+elmah#9108b48d3def87db

UPDATE

Try and identify where it is occurring. There may be several potential causes:

"Invalid Character in Base-64 String" using ASP.NET and C#

asp.net Invalid character in a Base-64 string

At the end of the day, if as you say, it is not causing any problem in production, then you can filter out these errors. Try setting EnableViewStateMac to false?

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-03-31 04:53

In my experience, this error tends to be cause by the user double-clicking on a button that triggers a postback. The second postback request cancels the first. The viewstate of the first request is only partially submitted, so it is invalid, but the error can't be sent to the browser because it has disconnected, which triggers the top-level error. This may be a bigger problem if the user doing something twice causes trouble. Otherwise, these errors can simply be filtered. Here's a good example of filtering out similar errors in ELMAH: https://stackoverflow.com/a/2549509/267448

If you're using ASP.NET WebForms, here's some code to disable the triggering control during postback: http://disturbedbuddha.wordpress.com/2007/12/10/disabling-a-trigger-control-during-asynchronous-postback/

Beware that if you disable an HTML <input type="submit"> button, it is excluded from your form variables, so your server-side Click event doesn't fire. Changing it to an <input type="button"> fixes that. In WebForms, that would be <asp:Button UseSubmitBehavior="False" />.

The above works with WebForms AJAX pages, but here's also a little bit of jQuery I came up with for other pages.

$(function () {
    $("a[href^='javascript']").click(function (event) {
        if (event.target.disabled)
            return false;
        event.target.disabled = true;
        setTimeout(function () {event.target.disabled = false;}, 250);
    });
});
查看更多
登录 后发表回答