首页 > 其他 > 详细

Cache使用

时间:2014-08-31 14:24:11      阅读:177      评论:0      收藏:0      [点我收藏+]

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");
    }

 

Cache使用

原文:http://www.cnblogs.com/liuswi/p/3947604.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!