Failed to load viewstate on NLB

℡╲_俬逩灬. 提交于 2021-02-07 08:29:10

问题


We have a system which dynamically creates the controls of a page every post back and handles back using the browser history and such.

The problem is that on the production server (2 nodes on NLB) we get randomly in differnet spots with no correlation we have found, a failed to load viewstate, the control tree might be different error. However, the exact same code on our staging server (same NLB setup as production) this has never happened.

I'm basically ruling out that its code at this point, since it doesnt happen in dev/staging or local enviroments at all, where on production it is fairly frequent. This is leading me to belive we have a configuration error, somewhere.

I have set hardcoded Machine keys in the web.config that is used on staging & production, and sessions are backed on MSSQL.

If anyone has suggestions to get me going in the right direction that would be great, our entire dev team is stumped by this.

Our webconfig is here at pastbin: http://pastebin.com/m2kRTd0k


回答1:


Here are a few things that you could check:

  • Are you sure that the web.config files you have edited are the ones that are used? Try putting a syntax error in them and see that you get an error.
  • Check that Sticky IP is not configured on your stage environment
  • Check that your environments are at the same patch level, maybe one has a different default value than the other.
  • There could also be a difference in the network infrastructure, where the 2 environments are located



回答2:


I have a dynamic questionnaire form in my company that is entirely database driven.

Since there are so many question types (e.g. yes/no, value based, multiple choice, sliders, multi-level drop downs, etc...), we have to create the form dynamically.

We would run into issues in production, but not on our dev or qa environment, similar to yourself; but our problem was the code. When we pushed the application to production, there were many more users running through so many more scenarios than we were ever able to in dev/qa.

Whenever we see the 'failed to load viewstate', doing one of these two things will usually solve the problem:

  • Create all the controls dynamically only in the INIT stage. It should be done here for the ViewState to work properly without much additional thought. ViewState is loaded after INIT completes and saves after PRERENDER completes. We can create the controls as late as the LOAD stage, but there may be nuances to the wiring. (http://msdn.microsoft.com/en-us/library/ms178472.aspx#general_page_lifecycle_stages)

  • Turn off AJAX and see if that fixes it (this is usually the culprit). If this fixes it, then we just have to check that there are no AJAX post backs that cause the page to change it's layout. An AJAX call may do something as simple as making a control invisible, or re-rendering a control with a new ID, causing the next next normal postback to detect changes in the control tree. If we have to make controls invisible through ajax, we just add the attribute('display','none') instead. After we are done with the changes, we turn AJAX back on.




回答3:


Does this happen for a variety of browsers? There are older versions of Safari and some proxy servers that would truncate the ViewState when it passes it back to the server.

One thing you might want to try to Chunking the viewstate. You can do that by setting the maxPageStateFieldLength attribute on the pages tag in your web.config. Here an example

<pages maxPageStateFieldLength="900">

Finally, you may want to consider not using clientSide viewstate at all. Here's an article that implements a serverside SQL based viewstate provider: http://www.codeproject.com/KB/viewstate/ViewStateProvider.aspx




回答4:


We had a very similar issue: “failed to load viewstate” errors occurred on load-balanced production servers, but we were not able to reproduce it on local/development servers (even when we added additional instance to have load balance on development site).

Finally we found that due to an error during deployment one of production servers had different version to the other and when user started on one server and continued to another (no Sticky IP configured), viewstate errors occurred.



来源:https://stackoverflow.com/questions/6572247/failed-to-load-viewstate-on-nlb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!