国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Session和Application在線用戶應用

2019-11-18 12:02:39
字體:
來源:轉載
供稿:網友

  Global.asxa
  
  using System;
  using System.Collections;
  using System.ComponentModel;
  using System.Web;
  using System.Web.sessionState;
  
  namespace elcare
  {
   /// <summary>
   /// Global
   /// </summary>
   public class Global : System.Web.Httpapplication
   {
   /// <summary>
  
   /// </summary>
  
   PRivate System.ComponentModel.IContainer components = null;
  
   public Global()
   {
    InitializeComponent();
   }
  
   protected void Application_Start(Object sender, EventArgs e)
   {
    Application["OL_UserCount"]=0;
   }
  
   protected void Session_Start(Object sender, EventArgs e)
   {
    Application.Lock();
    Application["OL_UserCount"]=(int)Application["OL_UserCount"]+1;//在線用戶
    Application.Add(Session.SessionID.ToString(),1);
    Application.UnLock();
   }
  
   protected void Application_BeginRequest(Object sender, EventArgs e)
   {
  
   }
  
   protected void Application_EndRequest(Object sender, EventArgs e)
   {
  
   }
  
   protected void Application_AuthenticateRequest(Object sender, EventArgs e)
   {
  
   }
  
   protected void Application_Error(Object sender, EventArgs e)
   {
  
   }
  
   protected void Session_End(Object sender, EventArgs e)
   {
    Application.Lock();
    Application.Remove(Session.SessionID.ToString());
    Application["OL_UserCount"]=(int)Application["OL_UserCount"]-1;
    Application.UnLock();
   }
  
   protected void Application_End(Object sender, EventArgs e)
   {
  
   }
  
   #region  /// <summary>
   /// </summary>
   private void InitializeComponent()
   {
    this.components = new System.ComponentModel.Container();
   }
   #endregion
   }
  }
  
  登陸驗證
   public void IdPassInSQL()
   {
    string strConn=(String) ((NameValueCollection) Context.GetConfig("system.web/database"))["strConn"];
    using (SqlConnection conn = new SqlConnection(strConn))
    {
    SqlCommand cmd = new SqlCommand("sp_IDPWD",conn);
    cmd.CommandType=CommandType.StoredProcedure;
    cmd.Parameters.Add("@ID",SqlDBType.VarChar,20);
    cmd.Parameters.Add("@PWD",SqlDbType.VarChar,20);
    cmd.Parameters["@ID"].Value=txtName.Text;
    cmd.Parameters["@PWD"].Value=txtPwd.Text;
    conn.Open();
  
    using (SqlDataReader dr = cmd.ExecuteReader())
    {
     if(dr.Read())
     {
     bool NotOL=true;
     for(int i=0;i<Application.Count;i++)
     {
      if(Application[Application.GetKey(i).ToString()].ToString()==dr["UserID"].ToString())
      NotOL=false;
     }
     if(NotOL)
     {
      Session["UserName"]=dr["UserName"].ToString(); //Session["UserName"] 用戶名字
      Session["UserID"]=dr["UserID"].ToString(); //Session["UserID"] 用戶ID
      Application[Session.SessionID.ToString()]=dr["UserID"].ToString();//給Session_Start生成的Application付用戶ID
      Response.Redirect("./main/main.aspx");
     }
     else
      message.Text="該用戶已登陸";
     }
     else
     {
     message.Text="密碼錯誤";
     }
    }
    }
   }
  
  注銷退出
   private void btnQuit_Click(object sender, System.EventArgs e)
   {
    Session.Abandon();//該語句將調用Global的Session_End事件
    Response.Write("<script language=javascript>parent.location='../default.aspx'</script>");//
   }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 望都县| 江川县| 大安市| 大同市| 丰城市| 无为县| 浦北县| 栖霞市| 六安市| 卢氏县| 台南县| 曲阜市| 宣化县| 克山县| 临邑县| 萨嘎县| 彭阳县| 广西| 精河县| 巴里| 开平市| 大荔县| 朝阳县| 长顺县| 安图县| 永兴县| 塔城市| 霍山县| 仙游县| 广河县| 遂平县| 沈丘县| 临沭县| 鹤峰县| 云梦县| 元朗区| 兴国县| 白朗县| 洛川县| 安西县| 柳林县|