Global.asax

(完整代码) 2KB

<%@ Application Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>


<script runat="server">
    string total; 
    void Application_Start(object sender, EventArgs e) 
    {
        // 在应用程序启动时运行的代码
        SqlConnection conn = DB.createCon();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "select total from admin";
        cmd.Connection = conn;
        total = Convert.ToString(cmd.ExecuteScalar());
        conn.Close();
        Application["total"] = total;
        Application["online"] = 0;
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  在应用程序关闭时运行的代码
        total = Application["total"].ToString();
        SqlConnection conn = DB.createCon();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "update admin set total='" + total + "'";  //注意,这里total要是string型的,不然,更新不进数据库里
        cmd.Connection = conn;
        cmd.ExecuteNonQuery();
        conn.Close();
    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // 在出现未处理的错误时运行的代码

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // 在新会话启动时运行的代码
        Application.Lock();
        Application["online"] = Convert.ToInt32(Application["online"]) + 1;
        Application["total"] = Convert.ToInt32(Application["total"]) + 1;
        Application.UnLock();
    }

    void Session_End(object sender, EventArgs e) 
    {
        // 在会话结束时运行的代码。 
        // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
        // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer 
        // 或 SQLServer,则不会引发该事件。
        Application.Lock();
        Application["online"] = Convert.ToInt32(Application["online"]) - 1;
        Application.UnLock();
    }
       
</script>

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。