且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在重定向到一个页面到另一个页面时清除一个页面的内存。

更新时间:2023-01-08 12:37:05

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.