locked
Intermittent ViewStateException: Invalid character in a Base-64 string RRS feed

  • Question

  • User681661554 posted

    Hi everyone,

     In my website happens sometimes (randomly) that after a postback there's an error whit viewstate: there are strange chars in it.

    It seems not to be the problem of "Application Pool Recycling" or running in a web farm (it's on a single server).

    Here's the generated exception:

    The state information is invalid for this page and might be corrupted.

    System.Web.UI.ViewStateException: Invalid viewstate.
    Client IP: 66.209.215.226
    Port: 3822
    User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
    ViewState: /wEWDALHnKLUCQKt/K+wCAKt/NevCALN58GSDAKh8+rTBAKawJeSCwLguMuQAwK3jrHwBgK3jsmHCgLj0�Q AtjktNUOAvTA1kM1/+/OQ1s9I8EUEbRClzU/cNroDw==
    Path: /works/SingleWork.aspx ---> System.FormatException: Invalid character in a Base-64 string.
    at System.Convert.FromBase64String(String s)
    at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
    at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)
    at System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded()

     

    As you can see there's a strange char in ViewState.

    I have absolutely no idea how it can happens and how to start searching for a solution...

    Anyone has an idea or suggestion?

    Thank you very much in advance...
     

    Friday, August 10, 2007 4:53 AM

Answers

  • User2032526919 posted

    @ joteke: the viewstate is not so large, but I'll try to check if the problem can be solved...

    The real problem is: why there are not-allowed chars in the viewstate? WHere they come from?!? It's really starnge... 

    As you can see by inspecting the stack trace of your error, exception is raised when ObjectStateFormatter is deserializing the ViewState string. And it calls Convert.FromBase64String to get the base 64-encoded srting to buffer of bytes (byte array). If you check documentation of Convert.FromBase64String, it raises FormatException when

    The length of s, ignoring white space characters, is not zero or a multiple of 4.

    -or-

    The format of s is invalid. s contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters.

    That's why I'm suspecting that the entire ViewState is not getting posted back which has had something to do, at least in other similar cases, with large ViewState. other option can be if you cause a postback before the page is fully loaded. That can also cause exception in ASP.NET 2.0.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 13, 2007 12:07 PM
  • User1981674846 posted

    Hi,
    There are several reason that may cause this issue.
    SYMPTOMS

    <script type=text/javascript>loadTOCNode(1, 'Symptoms');</script>
    There are several conditions that may cause this issue. Each known condition is presented with a short explanation and a possible workaround.
    Application Pool Recycling
    Server Farms or Server Clusters
    Form Posts
    Proxy servers and Virus Scanners

    RESOLUTION

    <script type=text/javascript>loadTOCNode(1, 'resolution');</script>
    1. Adjust the settings on the application pools so that recycling is less likely to occur at peak periods.
    2. Use a specific key in the machine.config to prevent automatic key generation on each process start
    3. Only post to the same ASPX page
    4. Turn off firewall and antivirus software
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 13, 2007 1:24 PM

All replies

  • User-868358626 posted

    Hi ,

         Could you please check out what kind of data you are storing in viewstate. Is this is a webfarm. If you are getting for a page then try turning off the viewstateencryption to never and see that helps or not.

    Thanks

    Rudra

     

    Friday, August 10, 2007 3:23 PM
  • User681661554 posted

    We get the error a very few times but in a lot of pages and with the same problem:
    "Invalid character in a Base-64 string".

    It seems that ViewState Data are corrupted when sent or posted back by the server... 

    In the view state there are standard data (there's not custom control that store data in viewstate), I'll try to change that settings. 

    Thanks for the suggestion! 

    Saturday, August 11, 2007 3:10 AM
  • User2032526919 posted

    Is the ViewState large on the pages where failing occurs? It could also be that you need to make asp.net to split it up a bit by setting maxPageStateFieldLength on <pages> element in web.config. For example

    <pages maxPageStateFieldLength="100" />

    when 100 means that single field is 100 characters long and entire data is split up into multiple __VIEWSTATE fields as needed.

    Note: This is available only in ASP.NET 2.0

    Sunday, August 12, 2007 5:48 AM
  • User681661554 posted

    @ neomax212000 : it seems that the problem is not realted to encryption...

    @ joteke: the viewstate is not so large, but I'll try to check if the problem can be solved...

    The real problem is: why there are not-allowed chars in the viewstate? WHere they come from?!? It's really starnge... 

    Monday, August 13, 2007 5:27 AM
  • User2032526919 posted

    @ joteke: the viewstate is not so large, but I'll try to check if the problem can be solved...

    The real problem is: why there are not-allowed chars in the viewstate? WHere they come from?!? It's really starnge... 

    As you can see by inspecting the stack trace of your error, exception is raised when ObjectStateFormatter is deserializing the ViewState string. And it calls Convert.FromBase64String to get the base 64-encoded srting to buffer of bytes (byte array). If you check documentation of Convert.FromBase64String, it raises FormatException when

    The length of s, ignoring white space characters, is not zero or a multiple of 4.

    -or-

    The format of s is invalid. s contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters.

    That's why I'm suspecting that the entire ViewState is not getting posted back which has had something to do, at least in other similar cases, with large ViewState. other option can be if you cause a postback before the page is fully loaded. That can also cause exception in ASP.NET 2.0.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 13, 2007 12:07 PM
  • User1981674846 posted

    Hi,
    There are several reason that may cause this issue.
    SYMPTOMS

    <script type=text/javascript>loadTOCNode(1, 'Symptoms');</script>
    There are several conditions that may cause this issue. Each known condition is presented with a short explanation and a possible workaround.
    Application Pool Recycling
    Server Farms or Server Clusters
    Form Posts
    Proxy servers and Virus Scanners

    RESOLUTION

    <script type=text/javascript>loadTOCNode(1, 'resolution');</script>
    1. Adjust the settings on the application pools so that recycling is less likely to occur at peak periods.
    2. Use a specific key in the machine.config to prevent automatic key generation on each process start
    3. Only post to the same ASPX page
    4. Turn off firewall and antivirus software
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 13, 2007 1:24 PM
  • User681661554 posted

    That's why I'm suspecting that the entire ViewState is not getting posted back which has had something to do, at least in other similar cases, with large ViewState. other option can be if you cause a postback before the page is fully loaded. That can also cause exception in ASP.NET 2.0.

     

    You're right... The viewstate was not sent back complete. In fact I moved the viewstate at the and of each page for SEO, but sometimes the postback occurred before tha page was full loaded.

     
    Now I've left the viewstate on top of the page and now all seems working ok...

    Thank you very much for helping me solving this "strange" problem!! 

    Monday, August 20, 2007 9:44 AM
  • User1480428627 posted

     Hi,

    this Microsoft Article might be of some help.

    http://support.microsoft.com/default.aspx?scid=kb;en-us;831150#1

    Sunday, August 26, 2007 2:02 AM
  • User-1383022055 posted

     Hi,

    How exactly did you solve this problem?  What do you mean by "move the viewstate to the top of the page?"  I'm getting this error intermittently too. 

    Thanks,

    figz 

    Tuesday, November 13, 2007 12:05 PM
  • User269846090 posted

    Ok, If I Turn Off firewall and antivirus software, the issue may cleared, Once it is cleared can i Turn on the firewall and Antivirus again?

    And is that same issue will happen in future once i turned on firewall? because, after i turned on,the same Code going to execute thats why asking.

    Saturday, April 13, 2013 7:35 AM