I've been trying to get to the bottom of the old Invalid length for a Base-64 char array and Invalid character in a Base-64 string.
It's a large ViewState, 开发者_Python百科as I'm storing a big chunk of data in there that I don't want the user requesting from the database every three seconds. Because it was so large (4 meg in some cases), I'm compressing it with Gzip, and overriding LoadPageStateFromPersistenceMedium() and SavePageStateToPersistenceMedium(ByVal pageViewState As Object) and creating a custom viewstate.
Problem is, every now and then the above error is occurring. I'm trying to get to the bottom of this, and so store in Session the initial View state length when calling SavePageStateToPersistenceMedium, and compare it with the new viewstate length in LoadPageStateFromPersistenceMedium. What I've noticed is that the Viewstate length has been severely cut, and I'm wondering what could be causing this.
I have also noticed + characters appearing in the second string (I was taking the rightmost 10 of each to see if anything was being added initially). It's also definitely happening more for one user than others, which either indicates issues with the data he deals with, or with his physical connection to the system (speed, software, browser etc).
Does anyone have any ideas? We also have a number of blades servicing the users, so I was wondering if it might be as a user to pushed from one to the other, but I need to check this.
I had also heard that it could be to do with rendering, but I thought viewstate was loaded before render?
As suggested in my comment above you should analyse, understand and decide if that amount of data really needs to be sent back and forth at every page load; if it belongs to the page and is used by some user controls or if it's only used by you in the code behind in some kind of hand made caching mechanism.
I don't repeat all articles you can find online, the alternatives are ViewState for small amount of data only relevant in that page and per request, Session as per user cache and Cache as per application cache.
Read this article for more details: How to Choose From Viewstate, Session, Application, Cache, and Cookies
First of all, you shouldn't be storing large chunks of data in ViewState. That's not what the ViewState was designed for, and it will kill the performance of your page.
You should always try limit the number of hits to the database, but not at the expense of everything else. You're putting an enormous amount of stress on the web server by forcing it to post and serve 5MB pages every request.
If the data is user-specific then store it in session. If the data is not user-specific, then it might be a good fit for caching. Whatever the case, do not put it in ViewState. Moving the data to Session should solve the problem.
精彩评论