如何在asp.net中清空会话 [英] how to blank session in asp.net

查看:68
本文介绍了如何在asp.net中清空会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生

我有两页正在使用分页.
在一页中,我每页的使用记录是20,但每页其他页的记录是150如何使用它
所以我正在使用会话进行缓存
一页

 如果会话(" )=   150" " 
       其他
           RecordPerPage = Application(" )
       结束 如果 


但听到的问题是,当我使用其他页面时,它不会空白Session("recordPerPage")
如何更正..


在此先感谢

解决方案

C#解决方案,您以后可以理解和翻译...

可以使用如下静态变量来代替Session:

static int recordPerPage = 20;


然后,在Page_Load()中:

if(Request.QueryString["Page"]!=null)
{
   if(Request.QueryString["Page"].ToString()=="2")
       recordPerPage = 150;
}



根据我的看法,以上所述是您解决问题的主要和正确的解决方案.不过,如果您想清除Session变量,则可以通过以下方式轻松实现:

Session["recordPerPage"] = "";


您必须执行此操作,因为会话变量不会在另一个页面调用/加载"中丢失其值.这是它们的主要属性,这就是为什么要使用它们.而且,如果您想清除它们的值,则必须通过给它们分配null或"值来手动清除它.


首先,我不确定为什么要使用Session来存储页面长度.它应该是应用程序/页面设置.在一个页面上将其设置为20,在另一页面上将其设置为150! br/> 如果您想清除会话值,则可以使用以下代码

Session("recordPerPage") = ""



在您的代码中,您还在Application对象中使用了相同的veriable,为什么呢?


Dear sir

i have a two page in which i am using pagination.
in one page i have use record per page is 20 but other page record per page is 150 how to use it
so i am using session for recodperpage
for one page

If Session("recordPerPage") = "150" Then
           RecordPerPage = "150"
       Else
           RecordPerPage = Application("RecordPerPage")
       End If


but hear problem is that when i use another page it does not blank Session("recordPerPage")
how to correct it..


thanks in advance

解决方案

Solution in C# which you can understand and translate later...

Instead of Session, you can use a static variable like:

static int recordPerPage = 20;


Then, in Page_Load():

if(Request.QueryString["Page"]!=null)
{
   if(Request.QueryString["Page"].ToString()=="2")
       recordPerPage = 150;
}



Above mentioned is the main and correct solution for your problem according to me. Still, if you want to clear the Session variable, you can do it easily by:

Session["recordPerPage"] = "";


You have to do this as Session variables do not lose their values on another Page call / Load. This is their main property and that''s why they are used. And if you want to clear their value, you have to clear it manually by assigning null or "" value to them.


First of all, I am not sure why are using Session to store the Page length. It should be an application/page setting instead. On one page set it 20 and 150 on another, that it!


There is no need to store record count in Session, you can directly get it by using GridView''s object.
if you want to clear session value then you can use following code

Session("recordPerPage") = ""



In your code you have use the same veriable in Application object also, why so ?


这篇关于如何在asp.net中清空会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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