VS2005中session的如何处理? 在VS2003里面global.asax里面直接有session_Start 但2005里面只有Application_Start,请教下 2005里面怎么处理啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一个是程序关闭和开始的时候是applicationsession是对话撒你直接设置session就行了然后在webconfig里把<system.web> <sessionState mode="InProc"> </sessionState>设置了才能生效给你个例子先定义一个Global.asax代码如下<%@ Application Language="C#" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><script runat="server"> string strcon =ConfigurationManager.AppSettings["sa"]; void Application_Start(object sender, EventArgs e) { Application["online"] = 0; Application["lishi"] = 0; //在应用程序启动时运行的代码 } void Application_End(object sender, EventArgs e) { //在应用程序关闭时运行的代码 } void Application_Error(object sender, EventArgs e) { //在出现未处理的错误时运行的代码 } void Session_Start(object sender, EventArgs e) { Session.Timeout = 1; SqlConnection cn = new SqlConnection(strcon); SqlCommand cmd = new SqlCommand("select * from Count", cn); cn.Open(); int cout = Convert.ToInt32(cmd.ExecuteScalar()); cn.Close(); Application.Lock(); Application["online"] = (int)Application["online"] + 1; Application["lishi"] = cout + 1; Application.UnLock(); //在新会话启动时运行的代码 } void Session_End(object sender, EventArgs e) { SqlConnection cn1 = new SqlConnection(strcon); SqlCommand cmd = new SqlCommand("update Count set Conutzuigaolishi=Conutzuigaolishi+1",cn1); cn1.Open(); cmd.ExecuteNonQuery(); cn1.Close(); //在会话结束时运行的代码。 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 // InProc 时,才会引发 Session_End 事件。如果会话模式 //设置为 StateServer 或 SQLServer,则不会引发该事件。 } </script>web文件中的代码 <system.web> <sessionState mode="InProc"> </sessionState>然后是主页拉两个lebal控件pageload事件中protected void Page_Load(object sender, EventArgs e) { this.Label1.Text = Application["online"].ToString(); this.Label2.Text = Application["lishi"].ToString(); } 请教:关于DataSet中的数据插入到数据库中 如何添加节点,使其成为树 如何写这个模糊查询? gridview编辑问题 各位高手指点一下 在线等 高手指点一下! asp后台管理系统有时候能登陆有时候却不能,怎么回事? owc问题? asp+asp.net群体(13110472)希望大家一起学习 如何在ASP.net中实现 在线用户列表 子窗口里怎么自动使用按键函数 提交的问题 request.form提取js动态生成的元素组的值 datalist删除多行记录
session是对话撒
你直接设置session就行了
然后在webconfig里把
<system.web>
<sessionState mode="InProc">
</sessionState>
设置了才能生效
给你个例子先定义一个Global.asax
代码如下
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %><script runat="server">
string strcon =ConfigurationManager.AppSettings["sa"];
void Application_Start(object sender, EventArgs e)
{
Application["online"] = 0;
Application["lishi"] = 0;
//在应用程序启动时运行的代码 }
void Application_End(object sender, EventArgs e)
{
//在应用程序关闭时运行的代码 }
void Application_Error(object sender, EventArgs e)
{
//在出现未处理的错误时运行的代码 } void Session_Start(object sender, EventArgs e)
{
Session.Timeout = 1;
SqlConnection cn = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("select * from Count", cn);
cn.Open();
int cout = Convert.ToInt32(cmd.ExecuteScalar());
cn.Close();
Application.Lock();
Application["online"] = (int)Application["online"] + 1;
Application["lishi"] = cout + 1;
Application.UnLock();
//在新会话启动时运行的代码 } void Session_End(object sender, EventArgs e)
{
SqlConnection cn1 = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("update Count set Conutzuigaolishi=Conutzuigaolishi+1",cn1);
cn1.Open();
cmd.ExecuteNonQuery();
cn1.Close();
//在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式
//设置为 StateServer 或 SQLServer,则不会引发该事件。 }
</script>web文件中的代码
<system.web>
<sessionState mode="InProc">
</sessionState>
然后是主页拉两个lebal控件
pageload事件中
protected void Page_Load(object sender, EventArgs e)
{
this.Label1.Text = Application["online"].ToString();
this.Label2.Text = Application["lishi"].ToString();
}