zoukankan      html  css  js  c++  java
  • asp.net读取与写入cookie的实例

    C#实现的读取与写入cookie的例子。

    代码如下:

    protected void Page_Load(object sender, EventArgs e)
    {
        //打开登录页面时获取客户端cookie值并写入前台控件中
        HttpCookie cookie = Request.Cookies["name"];
        if (cookie == null)
        {
          UserName.Text = "";
        }
        else
        {
           UserName.Text = cookie.Value;
        }
    }
     
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string username = Request.QueryString["UserName"];
        string password = Request.QueryString["PassWord"];
        if (登录成功)
        {
           Response.Write("登陆成功"); //www.jbxue.com
           HttpCookie cookie=new HttpCookie("name",username);//获取用户的用户名
           cookie.Expires = DateTime.Now.AddDays(10);//设置cookie过期时间为10天后
           Response.Cookies.Add(cookie);//将cookie写入客户端
        }
        else
        {
            Response.Write("登陆失败");
        }
    }

    本文出处参考:http://www.jbxue.com/article/8590.html

  • 相关阅读:
    Max Sum Plus Plus HDU
    Monkey and Banana HDU
    Ignatius and the Princess IV HDU
    Extended Traffic LightOJ
    Tram POJ
    Common Subsequence HDU
    最大连续子序列 HDU
    Max Sum HDU
    畅通工程再续
    River Hopscotch POJ
  • 原文地址:https://www.cnblogs.com/linuxnotes/p/3096151.html
Copyright © 2011-2022 走看看