I have a page with multiple user controls. For each control I stored state in a ViewState, but the size of page increased dramatically. So I've changed the code to store state in a session - Pros: page size is small, performance is pretty fast. But cons
are: session has a timeout, if IIS recycles I'm loosing my sessions.
My question is what is the best way of storing state of controls, additional data, etc. in ViewState or Session? or maybe there is another better way? Thanks.
---------------------------------------------
Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
Well, it's only proves my thoughts, but I don't see right now better solution. Because viewstate just slows down by moving data between browser and server.
I have a page with multiple user controls. For each control I stored state in a ViewState, but the size of page increased dramatically. So I've changed the code to store state in a session - Pros: page size is small, performance is pretty fast. But cons
are: session has a timeout, if IIS recycles I'm loosing my sessions.
My question is what is the best way of storing state of controls, additional data, etc. in ViewState or Session? or maybe there is another better way? Thanks.
alexnirvan thanks for your response.
session has a timeout - for this problem you have to set some of the configuration in web.config file like
this
if IIS recycles I'm loosing my sessions. - By default all sessions are stored in IIS only if you dont like to loose the session when you restart IIS then you have to store all the session within SQL server for this you have to set some configuration
within webconfig file like
this.
best way of storing state of controls - Its purely depend on your situation. Because Viewstate is storing in client side so fast retrieval, session are stored in server so all data can be collected from the server only but its secured one.
Any doubt please let me know
Any doubts please feel free to ask me. If this post is answer of your question then don't forgot to Click "Mark As Answer".
J.Jeyaseelan
When we can't use a viewstate (because of it size), I think session is also not good, because of timeouts (I don't think it's a good idea to increase session timeout time).
I'm still looking for other options to store controls state.
From your description, I think you want to increase the web performance.
I know the ViewState is not good for your requirement. but the Session is better for you.
If the Session object is TimeOut, you can check it and retrieve data from database.
Based on my experience, you can hide some data from the page. show them when it is necessary. by the way, you can try to Cache the data for single user. but that is not a good idea.
And, you can save the ViewState on the server.
For more information, please double check the following links:
alexnirvan
Member
7 Points
7 Posts
ViewState vs Session
Jul 13, 2009 12:39 AM|LINK
I have a page with multiple user controls. For each control I stored state in a ViewState, but the size of page increased dramatically. So I've changed the code to store state in a session - Pros: page size is small, performance is pretty fast. But cons are: session has a timeout, if IIS recycles I'm loosing my sessions.
My question is what is the best way of storing state of controls, additional data, etc. in ViewState or Session? or maybe there is another better way? Thanks.
Session view state
khparhami
Member
447 Points
194 Posts
Re: ViewState vs Session
Jul 13, 2009 03:05 AM|LINK
Hi,
Please have a look :
http://weblogs.asp.net/pleloup/archive/2006/06/28/454931.aspx
good luck
Khashayar
---------------------------------------------
Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
alexnirvan
Member
7 Points
7 Posts
Re: ViewState vs Session
Jul 13, 2009 03:33 AM|LINK
Well, it's only proves my thoughts, but I don't see right now better solution. Because viewstate just slows down by moving data between browser and server.
jeyaseelan@a...
Contributor
5124 Points
2025 Posts
Re: ViewState vs Session
Jul 13, 2009 07:43 AM|LINK
alexnirvan thanks for your response.
session has a timeout - for this problem you have to set some of the configuration in web.config file like this
if IIS recycles I'm loosing my sessions. - By default all sessions are stored in IIS only if you dont like to loose the session when you restart IIS then you have to store all the session within SQL server for this you have to set some configuration within webconfig file like this.
best way of storing state of controls - Its purely depend on your situation. Because Viewstate is storing in client side so fast retrieval, session are stored in server so all data can be collected from the server only but its secured one.
Any doubt please let me know
J.Jeyaseelan
alexnirvan
Member
7 Points
7 Posts
Re: ViewState vs Session
Jul 13, 2009 02:31 PM|LINK
Well, of course it depends on situation.
When we can't use a viewstate (because of it size), I think session is also not good, because of timeouts (I don't think it's a good idea to increase session timeout time).
I'm still looking for other options to store controls state.
Bober Song -...
All-Star
34686 Points
2167 Posts
Re: ViewState vs Session
Jul 14, 2009 03:16 AM|LINK
Hi alexnirvan,
From your description, I think you want to increase the web performance.
I know the ViewState is not good for your requirement. but the Session is better for you.
If the Session object is TimeOut, you can check it and retrieve data from database.
Based on my experience, you can hide some data from the page. show them when it is necessary. by the way, you can try to Cache the data for single user. but that is not a good idea.
And, you can save the ViewState on the server.
For more information, please double check the following links:
http://weblogs.asp.net/pwilson/archive/2003/08/21/24866.aspx
http://sjc.ironspeed.com/post?id=323963
Save ViewState On The File System
http://www.codeproject.com/KB/aspnet/SaveViewState.aspx
http://www.codeproject.com/KB/viewstate/ServerViewState.aspx
http://aspalliance.com/72
http://www.xepient.com/viewstateserver.aspx
http://www.eggheadcafe.com/articles/20040613.asp
http://aspguy.wordpress.com/2008/07/09/reducing-the-page-size-by-storing-viewstate-on-server/
I hope it is helpful to you.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
alexnirvan
Member
7 Points
7 Posts
Re: ViewState vs Session
Jul 14, 2009 04:00 AM|LINK
Bober Song,
It is exactly what I was looking for. Very helpful links.
Thank you!