如何在重定向到一个页面到另一个页面时清除一个页面的内存。 [英] how to clear memory of one page when redirect to one page to other page.

查看:125
本文介绍了如何在重定向到一个页面到另一个页面时清除一个页面的内存。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个多表格的网站。每个页面都使用了视图状态和不同的会话变量以及一些用于执行插入/更新验证和操作的隐藏值。现在,当用户重定向到下一页时,它会自动清除视图状态/会话变量。我认为我们手动需要清除会话变量但不知道viewstate。



主要关心在某些页面中,会话中存储了一个包含近1000行的完整数据集或数据表,我认为这会影响站点性能。



有人可以帮助我。

Hi all,

i have a website with multi forms. each page has used viewstates and different session variables and + some hidden values which are used for doing insert / update validation and operation. now when user redirect to next page does it auto clear the viewstate/session variables.i think we manually need to clear session variable but no idea about viewstate.

main concern is that in some pages a complete dataset or datatable with almost 1000 of rows are stored in session and i think this will affect the site performance.

can someone please help me.

推荐答案

1.Viewstate是一个保存到Web的缓存页面本身主要用于保留页面回发之间的数据,并在重定向到其他页面时自动丢失。

2.会话是与访问Web应用程序的每个用户关联的缓存,因此它存在于用户级别,用于现有应用程序的所有网页。因此,在您的代码中,您应该在重定向到其他页面之前从会话中删除不需要的数据。

删除示例 this.Session [MyRows] = null;



结论是Session应仅用于保留所有页面中所需的一些常规参数(如用户ID和权限),或者可用于在页面之间发送参数 - 但是这种情况下,你得到参数后,你必须从会话缓存中删除它们!
1.The Viewstate is a cache saved into the Web Page itself, is used mainly to preserve data between page postbacks and will be automatically lost when you redirect to other page.
2.The Session is a cache associated with each user that access a web application, so it exist at the user level for all web pages of an existing application. So in your code, you should delete the unwanted data from your Session before to redirect to other page.
Example for delete: this.Session["MyRows"]=null;

The conclusion is that the Session should be used only to keep some general parameters that are needed in all pages (like user ID and rights), or can be used to send parameters between pages- but in this case after you get the parameters you have to delete them from the Session cache!


劳尔提供的好评论。只是想重申一下,避免使用Session来存储包含大量行的数据集。永远记住,Session是特定于用户的,如果我们存储大量数据,它会为每个使用服务器资源的用户单独存储和保存它。



这将是一个巨大的数据当网站有更多并发用户时会产生影响。最好存储在ViewState中,因为它将位于Cilent Side,不会消耗任何服务器资源并在重定向到另一个页面时清除。此外,也可以使用缓存,它存储在服务器端,但只包含一个将在用户之间共享的复制,如果数据不经常更改,则应该使用。
Good comments provided by Raul. Just wanted to reiterate that avoid Session being used for storing Dataset which contains large number of Rows. Always remember that, Session is User specific, and if we store large data it stores and holds it separately for each User consuming the Server Resources.

This will be a huge impact when there are more number of concurrent users for the Website. Would be better to Store in a ViewState, since it will be on the Cilent Side ,wont be consuming any Server Resources and cleared once redirected to another Page . Also, Can use Cache too, which stores at Server Side, but Contains only a single Copy which will be shared across the Users and should be used if Data is not frequently changed.


Session [ Session] = null;



这会删除会话。
Session["Session"] = null;

this will remove session.


这篇关于如何在重定向到一个页面到另一个页面时清除一个页面的内存。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆