1

In our website (ASP.NET Forms, Sitecore 6.6), in the log files I find so many viewstate exceptions. But there is no obvious issues reported by the users.

Here is the exception, by referring to the log files I found that this issue mainly occurs in a particular page which has a viewstate like 20KB. Please help to sort out this issue.

5676 00:30:43 ERROR Application error. 
Exception: System.Web.HttpException 
Message: The client disconnected. 
Source: System.Web 
at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) 
at System.Web.UI.HiddenFieldPageStatePersister.Load() 
at System.Web.UI.Page.LoadPageStateFromPersistenceMedium() 
at System.Web.UI.Page.LoadAllState() 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.ProcessRequest() 
at System.Web.UI.Page.ProcessRequest(HttpContext context) 
at System.Web.UI.Page.ProcessRequest(HttpContext context) 
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

Nested Exception 

Exception: System.Web.UI.ViewStateException 
Message: Invalid viewstate. 
Client IP: xxx.xxx.xxx.249 
Port: 53377 
Referer: <URL>
Path: /<PATH>
User-Agent: Mozilla/5.0 (iPad; CPU OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25 
ViewState: cT4jo/ieR1NMvyqfwH6MToZmW6E/oKO64RcFXyllzcXB84wiWN/j3WeRyXxUZWCnr9c6staUp76B0Zr7/IqYgWWS3qfiMu9xzpU61bB+TAjDz0IbVwSt0rvZoFh7M/tQGQWyRha4ieCH7B5wKu3hXexRTIWwvP0JLbNmnQyFnOdqTnJZXBYQtaTyzMva3Fy7Q9YNstymtd1XrO1WHvUsBS6CwyV8eUYZs3LWRvczf3Ixz2XRg2Y4fY4kpuXl+QJLkbhgnALcFeGe9ur1l8Gyq6EdhqRb0BOlK4ozKaq4hpUT6HWes9YP2DjCJCpa2wP47hqZ5DaAXrcN+R6UPOqYIl6TSIjNUCv35NPPozaFjItLGmZi6ee+PfxOSz4ejxgBJzV3KNf2/1Mr5GNI7uZWgw998CI0mtxtpuWjp5kZCAfKzSCX//Vv7030VBLAE4Gj1RYIek1WNuwDreglFE5Pt8uKMDOsJstt8tXGqyCVcxqQAnRyN51e3uuqbDvDL2yVXA6yv6QyaCD/XmIHcgz//HItyqlhEziyOx7MxwKzpMyLu/6g2poqKMoNWtnQwxw9JTVwijEf45Lai+BOmgMNITgyrmLDp7ioHgHFK0VSmrSxN2W+CBRyyXWfn3QAy8UQYpq1TdHEUnGbc3XTTfBYW/gj+mFGaEpM24hUi/gJBxU2r+/wG2XxHfsxgrq6kG5cM8Hzf4GHuSC4...

Nested Exception 

Exception: System.FormatException 
Message: Invalid length for a Base-64 char array or string. 
Source: mscorlib 
at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) 
at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) 
at System.Convert.FromBase64String(String s) 
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) 
at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) 
at System.Web.UI.HiddenFieldPageStatePersister.Load() 
Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
Dhanuka777
  • 8,331
  • 7
  • 70
  • 126
  • 1
    Please look at http://stackoverflow.com/questions/16395715/system-web-ui-viewstateexception-invalid-viewstate post. You may get help from this. – mit Oct 14 '13 at 07:19
  • More information, Client IP: 121.127.207.249 Port: 53377 – Dhanuka777 Oct 14 '13 at 07:31
  • Hi mit, in the above post you mentioned, Bluebird used viewstate compression mentioned in "http://www.codeproject.com/Articles/14733/ViewState-Compression". Our website is heavily used (100 users at a given time accessing the particular page which throws the viewstate exception). Will this affect performance badly if I try to compress viewstate? – Dhanuka777 Oct 14 '13 at 07:34
  • possible duplicate of [Viewstate exception Validation of viewstate MAC failed](http://stackoverflow.com/questions/19355196/viewstate-exception-validation-of-viewstate-mac-failed) – Yan Sklyarenko Oct 14 '13 at 10:38
  • The the front-end site being access load balanced? Is the UI component (sublayout, WebControl) that generates this error HTML cached by Sitecore? – Mark Ursino Oct 24 '13 at 16:49
  • Hi Mark, Front end site being access load balanced. UI component is not HTML cached. – Dhanuka777 Oct 25 '13 at 05:05

2 Answers2

2

We have also seen this on our load balanced servers, specifically on pages where we use some form of ajax control (either ajax control toolkit, or home-grown). The issue appears to be that the customer invokes some form of ajax request, then either closes their browser or goes to a different page either by a link or the browser back/forward controls.

One thing you can do, if you have control over when your response is sent to the client, is to do the following:

if(HttpContext.Current.Response.IsClientConnceted) {
    //Send response
}

This should remove the error from your logs.

  • What do you mean by "if you have control over when your response is sent to the client"? – Krisztián Balla Jan 14 '14 at 10:49
  • It may be that the thing that is actually causing the error is a third party handler that you do not have the source to. Unless the code is written in a way you can derive the source class and override that little bit of code easily, you are probably out of luck. – Owen Martin Jan 18 '14 at 12:19
  • 1
    Where would you add your code snippet in an ordinary ASP.NET WebForms application? Is it needed at all? – Krisztián Balla Jan 20 '14 at 06:46
1

I've seen this same exception message in our logs for some time now and I have never been able to reproduce the issue until today, so I thought that I'd share my experience.

On a page using Ajax Update Panels, the user can first load the page. Then the user can invoke an Ajax request. If the user invokes another Ajax request, but hits the back button before the second Ajax request finished loading then the user is redirected to the previous page and the exception message is logged.

The user experience is not interrupted when this message is logged and therefore, the user doesn't know that anything happened behind the scenes. The exception message is accurate in terms of how view state is handled in the ASP.Net page life cycle.

I would say that the exception message is safe to ignore and you could likely find a solution to avoid having the exception message logged in the first place.

As a note, adding machine keys or addressing web server config settings has never helped me in any case regarding this exception message primarily because, in most cases, I was not using a web farm.