Strategies for reducing ViewState size in asp.net

后端 未结 6 1562
星月不相逢
星月不相逢 2021-01-12 18:17

I use \'n\' number of server controls in my page. Now I am into performance tuning and I\'ve noticed that my ViewState is too large and it makes my page slow.<

6条回答
  •  无人及你
    2021-01-12 18:51

    Viewstates should only be used when you need to remember the state of the page between postbacks. It's used to prevent extra access to the database. So, if this isn't required in your control, use EnableViewState = False. If nothing on your page is going to need a viewstate, you can disable viewstates for that page by adding EnableViewState = False within the Page tag.

    If your server can afford it, you may want to transfer data into Sessions. Do this if necessary for security (viewstate should not contain sensitive data), or if your viewstate is holding a large amount of data. Be careful as, by default, Sessions are stored in memory of the server. Therefore, you don't want to use this too much with large data if you're expecting many concurrent users. You can, however, change where the Session is stored (i.e. another server).

提交回复
热议问题