Does viewstate expire?

2019-01-14 21:06发布

Let's say you have a aspx page that does not rely on session, but does rely on viewstate for persistance between postbacks.

If a user is accessing this page, and leaves for a long lunch, will viewstate still be valid when he returns?

12条回答
beautiful°
2楼-- · 2019-01-14 21:31

Viewstate does not expire, as long as they are still on the page, it will still be there and functional.

查看更多
【Aperson】
3楼-- · 2019-01-14 21:39

Viewstate does not expire.

All viewstate data is stored on the client and is submitted back to the server when the user executes a postback.

This has some very interesting implications, and is explained very thoroughly here.

查看更多
来,给爷笑一个
4楼-- · 2019-01-14 21:40

No ViewState is kept as part of the PostBack process. You can, however, override the Page class's SavePageStateToPersistenceMedium() and LoadPageStateFromPersistenceMedium(), to implement that behavior if desired. For more information read Understanding the ASP.NET ViewState.

Note that Page ViewState is stored in the Session so if your Session expires, the ViewState will be lost. I wouldn't say this is ViewState expiring, but yes, it will be destroyed after Session timeout.

查看更多
不美不萌又怎样
5楼-- · 2019-01-14 21:41

ViewState is kept in a hidden field on the page itself. So as long as the user has the page, he'll have the ViewState. But if your app automatically logs the user out after a certain period of time, still having the ViewState may not do him any good.

查看更多
聊天终结者
6楼-- · 2019-01-14 21:42

By default, Viewstate is included with the html content as a hidden input. That means it won't expire, but that everything in viewstate must be uploaded from the user's browser. Since that's typically the slowest part of the connection in a public site, putting a lot of stuff in viewstate can quickly make your site seem very slow.

查看更多
Root(大扎)
7楼-- · 2019-01-14 21:43

Yes, ViewState expires in certain conditions. For example when you are using iframe:s, or when you are upkeeping "live" connection to the server with regular postbacks. Then you might want to investigate this option: <sessionPageState historySize="9"/>, which actually hard-codes how many "postback results" are stored in the Session (if SessionPageStatePerster is used). Each postback stores it's ViewState to the end of the Queue in Session["__VIEWSTATEQUEUE"], and deletes ViewStates that are "too old". And how do you think SessionPageStatePerster decides which ViewStates are too old.. by configuring some arbitrary historySize-constant in web.config.. Omg! It too me forever to find this problem... My hatred toward asp.net programming is undescribable now.. grrr...

查看更多
登录 后发表回答