Erratic Invalid Viewstate issue in a .NET application

前端 未结 10 1630
长发绾君心
长发绾君心 2020-12-04 06:21

I seem to be getting a \"invalid viewstate\" every now and then in the event viewer for my ASP.NET application.

Most of them (95%) seem to be referencing Scrip

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 07:10

    Viewstate issues are annoying and frustrating - I've noticed a few people have talked about having Viewstate issues in this thread. So, here are some suggestions you can look at in order.

    1. I'd echo what Freddy Rios has said in the thread already. Make sure that you've hardcoded the machine key. This will solve the vast majority of these issues. The important thing about the ScriptResource link is that it should have a d parameter and a t parameter in the querystring. If it doesn't something else is wrong!

    2. Don't let the user postback until your done. You could probably do this with javascript and a bit of css. From memory, I think there is a way to do this with a meta tag but it might be IE only.

    3. I would look at is flushing the response early. I would think after the script manager would be best. But you might need to experiment a bit.

    4. If your viewstate looks bloated, turn on GZip compression on in IIS.

    5. If your viewstate has became really bloated and you can't get GZip compression turned on/or it has an undesired side affect. Then you can compress and uncompress the viewstate. http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx

    6. If that still leaves you with a bloated viewstate, you could look at storing the viewstate locally. http://blog.arctus.co.uk/articles/2007/04/23/advanced-asp-net-storing-viewstate-in-a-database/ is a good starting point.

提交回复
热议问题