会话和申请柜台 [英] session & application counter
本文介绍了会话和申请柜台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想了解asp.net中有关会话和应用程序变量的简单示例.
我已经创建了3个页面,我正在从a导航到b,从b导航到c,然后再次从c导航到a.我希望会话计数器增加1.当我返回到"a"页时.但是会话计数器将增加2,而不是1.
请提出所需的输出.
在此先感谢..
Hi,
Would like to know simple examples on Session & application variable in asp.net.
I have created 3 pages, I am navigating from a to b, b to c, & again c to a. I would like to have the session counter to increase by 1. When i return back on pag e ''a''. But the session counter is increasing by 2 instead of 1.
Kindly suggest the desired output.
Thanks in advance..
推荐答案
这里是解决此问题的快速方法.
首先,创建一个将处理您的SessionCounter的类;
Here''s a quick fix for that.
First, create a class that will handle your SessionCounter;
public class SessionCounter {
public SessionCounter() {
Counter = 1;
LastPage = "A";
}
public int Counter { get; set; }
public string LastPage { get; set; }
}
然后在您的网页上将此内容插入您的Page_Load
Then on your webpage insert this on your Page_Load
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
SessionCounter sc = new SessionCounter();
if (Session["SessionCounter"] != null) {
sc = (SessionCounter)Session["SessionCounter"];
//put your page letter here as the last page to trigger the increment
//In your case, its page C
if (sc.LastPage == "C") {
sc.Counter++;
}
//put your page letter here (sample is for page A)
//update this per page
sc.LastPage = "A";
}
Session["SessionCounter"] = sc;
}
}
祝你好运!
Good luck!
这篇关于会话和申请柜台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文