Which one is more costilier View State or Session?
Which one more costilier View State or Session when a bulk dat开发者_StackOverflow中文版a is stored. Why?
Depends on your point of view and usage, but generally session is cheaper all around.
For the client, session is nearly free. It only has to deal with keeping up with a session cookie (or the session id via the url if you configured for cookieless sessions). Viewstate pushes all the data to the client, in the text of the page source.
For the server, session and viewstate both have a cost. viewstate has to be serialized and deserialized and moved across the wire. Session is stored in memory (unless configured otherwise) but doesn't have to be manipulated. So session uses more storage in memory over a longer period of time, viewstate creates temporary memory use and higher cpu hits. So it depends on how much data, how often the client is communicating with the server, and which resources you want to conserve... though in general, with bulk data, session would win hands-down in almost all practical cases.
ViewState will cost bandwidth and make your pages heftier while the Session will cost memory on the server or some other server if out-of-proc is used.
精彩评论