zoukankan      html  css  js  c++  java
  • 使用Cache防止多人同时修改同一条信息

    Default.aspx:

    <a href="Default2.aspx?id=123&type=11ad">打开第二个页面id=123</a><br>
    <a href="Default2.aspx?id=12&type=11ad">打开第二个页面id=12</a>

    Default2.aspx:

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    protected void Page_Load(object sender, EventArgs e)
        {
            string type = Request.QueryString["type"].ToString();
            if (!IsPostBack)
            {
                if (Cache["'" + type + "'"] == null)
                {
                    msg();
                }
                else
                {
                    if (Cache["'" + type + "'"].ToString() == Request.QueryString["id"].ToString())
                    {
                        Label1.Text = "我可以进入这个页面";
                    }
                    else
                    {
                        Label1.Text = "有人已经进入该页面,请稍后。。。";
                        Button1.Visible = false;
                    }
                }
            }
            
        }
        
        private void msg()
        {
            string type = Request.QueryString["type"];
            //Cache["'" + type + "'"] = Request.QueryString["id"].ToString();
            Cache.Insert("'"+type+"'", Request.QueryString["id"].ToString(), null, DateTime.Now.AddSeconds(10), TimeSpan.Zero);
            Label1.Text = "我可以进入这个页面";
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string type = Request.QueryString["type"];
            Cache.Remove("'" + type + "'");
            Response.Redirect("Default.aspx");
        }
  • 相关阅读:
    最大熵模型中的数学推导
    最大似然估计总结
    减压放松的一些网站
    决策树
    【转】贝叶斯分类干货
    【转】数学之美番外篇:平凡而又神奇的贝叶斯方法
    信号量与并发控制
    枚举与字符串映射
    Block与参数
    Sublime Text 小计
  • 原文地址:https://www.cnblogs.com/liuswi/p/3947604.html
Copyright © 2011-2022 走看看