views:

160

answers:

2

I'm getting the following error in my ASP.net web page:

Invalid length for a Base-64 char array.

This happens when a user activates an ajax request before the previous request completes. How can I prevent this error from occurring?

edit: here's the stack trace. Because the error doesn't appear to be happening in my own code, I'm not sure what to do.

at System.Convert.FromBase64String(String s) at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) at System.Web.UI.HiddenFieldPageStatePersister.Load()

A: 

Base64 strings have a length that is a multiple of three. While I cannot tell where the invalid Base64 string comes from it seems obvious that some code is trying to decode an string that is either a corrupted Base64 string or not a Base64 string at all.

Daniel Brückner
Here's the stack trace. Because the error doesn't appear to be happening in my own code, I'm not sure what to do.at System.Convert.FromBase64String(String s) at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) at System.Web.UI.HiddenFieldPageStatePersister.Load()
Scott Bedwell
It seems quite obvious that your application crashes while it tries to decode the view state because the value is not a valid Base64 string. So you have to find out why the view state is no longer valid.
Daniel Brückner
A: 

You could try and prevent subsequent requests during the ajax request:

function OnRequestStart(sender, args) {
                if (args.EventTargetElement) {
                    var control = document.getElementById("<%= SomeButton.ClientID %>");
                    if (control != null) {
                        if (args.EventTargetElement.id == control .id) {
                            control .disabled = true;
                        }
                    }
                }
            }
            function OnResponseEnd(sender, args) {
                if (args.EventTargetElement) {
                    var control = document.getElementById("<%= SomeButton.ClientID %>");
                    if (control != null) {
                        if (args.EventTargetElement.id == control .id) {
                            control .disabled = false;
                        }
                    }
                }
            }
Coov
I really suggest trying to find and fix a bug first instead of just hiding it.
Daniel Brückner