• Asp.net 之Application


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Application["App1"] = "value1";
            Application["App2"] = "value2";
            Application["App3"] = "value3";
            int N;
            for (N = 0; N < Application.Count; N++) 
            {
                Response.Write("变量名:" + Application.GetKey(N));
                Response.Write("变量值:" + Application.Get(N) + "</br>");
            }
            Application.Lock();
            Application["App1"] = "zhang";
            Application["App2"] = "wang";
            Application["App3"] = "li";
            Application.UnLock();
    
            //修改后的变量
            Response.Write("修改后的变量值</br>");
            for (N = 0; N < Application.Count; N++) 
            {
                Response.Write("变量名:" + Application.GetKey(N));
                Response.Write("变量值:" + Application.Get(N) + "</br>");
            }
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Application.Lock();
    
            Application["PageClick"] = (int)Application["PageClick"] + 1;
            Application["UserVisit"] = (int)Application["UserVisit"] + 1;
    
            Application.UnLock();
    
            Response.Write(string.Format("页面单击数:{0}<br/>", Application["PageClick"]));
    
            Response.Write(string.Format("用户访问数:{0}<br/>", Application["UserVisit"]));
        }
    }
    

      

    <%@ Application Language="C#" %>
    
    <script runat="server">
    
        void Application_Start(object sender, EventArgs e) 
        {
            //在应用程序启动时运行的代码
           Application["count"] = 0;
          
    
        }
        
        void Application_End(object sender, EventArgs e) 
        {
            //在应用程序关闭时运行的代码
    
        }
            
        void Application_Error(object sender, EventArgs e) 
        { 
            //在出现未处理的错误时运行的代码
    
        }
    
        void Session_Start(object sender, EventArgs e) 
        {
            //在新会话启动时运行的代码
            Application.Lock();
            Application["count"] = (int)Application["count"] + 1;
            Application.UnLock();
    
        }
    
        void Session_End(object sender, EventArgs e) 
        {
            //在会话结束时运行的代码。 
            // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
            // InProc 时,才会引发 Session_End 事件。如果会话模式 
            //设置为 StateServer 或 SQLServer,则不会引发该事件。
            Application.Lock();
            Application["count"] = (int)Application["count"] -1;
            Application.UnLock();
    
        }
           
    </script>
    

      

  • 相关阅读:
    写个简单的搜索引擎
    C++中的三种继承关系
    《深度探索C++对象模型》调用虚函数
    一次数据库优化的对话
    读后感:你的灯亮着吗
    Linux Shell 截取字符串
    一次关于知识储备的思考
    哈夫曼树与哈夫曼编码
    二叉查找树
    jar中没有注清单属性
  • 原文地址:https://www.cnblogs.com/mengluo/p/6021787.html
Copyright © 2020-2023  润新知