Global00.asax.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:5k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Net;
- using System.Collections;
- using System.ComponentModel;
- using System.Web;
- using System.IO;
- using System.Data;
- using System.Data.SqlClient;
- using System.Web.SessionState;
- namespace insideweb
- {
- /// <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["user_sessions"] = 0;
- }
- protected void Session_Start(Object sender, EventArgs e)
- {
- Int32 count;
- string UserHostAddress;
- string UserHostName;
- SqlConnection MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- if (Session["whenLogin"]==null)
- {
- Response.Redirect("index.htm");
- Session["whenLogin"]="now";
- }
- if(Session["online"]==null)
- {
- Application.Lock();
- Application["user_sessions"] = (int)Application["user_sessions"] + 1;
- Application.UnLock();
- UserHostAddress=Request.UserHostAddress ;
- IPHostEntry myHost = Dns.GetHostByAddress(Request.UserHostAddress);
- UserHostName=myHost.HostName;
- try
- {
- Application["UserHostName"]=myHost.HostName;
- Application["IP"]=UserHostAddress;
- SqlCommand MyCommand0 = new SqlCommand("SELECT * FROM OnlineUser WHERE IP=@IP",MyConnection);
- MyCommand0.CommandType = CommandType.StoredProcedure;
- MyCommand0.Parameters.Add(new SqlParameter("@IP",SqlDbType.NVarChar, 50));
- MyCommand0.Parameters["@IP"].Value = Request.UserHostAddress;
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- count = (Int32)MyCommand0.ExecuteScalar();
- MyConnection.Close();
- }
- finally
- {
- }
- if(count <0)
- {
- try
- {
- MyConnection.Open();
- SqlCommand MyCommand=new SqlCommand("Insert INTO OnlineUser(IP,UserHostName) values (@IP,@UserHostName)",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@IP",SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@IP"].Value = UserHostAddress;
- MyCommand.Parameters.Add(new SqlParameter("@UserHostName", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@UserHostName"].Value = UserHostName;
- MyCommand.ExecuteNonQuery();
- MyConnection.Close();
- }
- catch
- {
- }
- }
- else
- {
- try
- {
- DateTime now1= DateTime.Now;
- MyConnection.Open();
- SqlCommand MyCommand1=new SqlCommand("Update OnlineUser Set UserHostName=@UserHostName WHERE IP=@IP",MyConnection);
- MyCommand1.CommandType = CommandType.StoredProcedure;
- MyCommand1.Parameters.Add(new SqlParameter("@IP",SqlDbType.NVarChar, 50));
- MyCommand1.Parameters["@IP"].Value = UserHostAddress;
- MyCommand.Parameters.Add(new SqlParameter("@UserHostName", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@UserHostName"].Value = UserHostName;
- MyCommand1.ExecuteNonQuery();
- MyConnection.Close();
- }
- catch
- {
- }
- }
- Session["online"]="set";
- }
- }
- 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["user_sessions"] = (int)Application["user_sessions"] - 1;
- Application.UnLock();
- SqlConnection MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand MyCommand2=new SqlCommand("Delete from OnlineUser where IP=@IP",MyConnection);
- MyCommand2.Parameters.Add(new SqlParameter("@IP", SqlDbType.NVarChar, 50));
- MyCommand2.Parameters["@IP"].Value = Application["IP"];
- MyCommand2.Connection.Open();
- try
- {
- MyCommand2.ExecuteNonQuery();
- }
- catch (SqlException)
- {
- }
- MyCommand2.Connection.Close();
- }
- protected void Application_End(Object sender, EventArgs e)
- {
- }
- #region Web 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- }
- #endregion
- }
- }