![]() |
ASP.NET统计点击次数:
1.新建Global.asax(
void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
Application.Lock();//修改时必须先锁定,锁定防止与其他电脑同时更改造成错误
Application["count"] = (int)Application["count"] + 1;//整个解决方案全局变量,在各个网页传递值
Application.UnLock();//解锁
}
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
Application["count"] = (int)Application["count"] + 1;
Label2.Text = "点击按钮的次数: "+Application["cishu"].ToString();
Label1.Text = "";
Label3.Text = Page.Form.ToString();
Response.Redirect("default.aspx?bz=1");//网页间用BZ传递,下句是判断有没有值
if (!(Request.QueryString["bz"] == null || Request.QueryString["bz"] == ""))//网页间传递变量值
{
// Label2.Text = "无";
}
else
if(Session["user"] == null || Session["user"].ToString() == "")
{
Response.Write("<script>alert('因为SESSION原因您必须登录才能使用');window.location.href='login.aspx';</script>");
} }
if (Request.Cookies["name"] == null || Request.Cookies["name"].Value == "") //读取cookie的值
//if Request.Cookies["name"] = null && Request.Cookies["name"].Value = "")
//判断cookies是否为空
//
HttpCookie hc = new HttpCookie("name"); //设定COOKIE的值
hc["name"] = name;
hc.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(hc);
// txttmp.Text = hc.Expires.ToString();
//Session.Clear;
Response.Redirect("default.aspx?bz=1");
Edi
Region1