zoukankan      html  css  js  c++  java
  • Cookie和Session

    Cookie例子

    HttpCookie cookie = new HttpCookie("mjsclient");
    if (cb_remeberme.Checked)
    {
    cookie.Expires = System.DateTime.Now.AddDays(7);
    }
    cookie.Values["Company"] = Server.UrlEncode(sCompany);
    cookie.Values["UserName"] = Server.UrlEncode(sUsername);
    cookie.Values["PWD"] = Server.UrlEncode(sPwd);
    cookie.Values["NickName"] = Server.UrlEncode(ds.Tables[0].Rows[0]["nickname"].ToString());
    Response.Cookies.Add(cookie);


    //接收

    if (Request.Cookies["mjsclient"] != null)
    {
    rm.a_id = Convert.ToInt32(Request.Cookies["mjsclient"]["UserName"]);
    }

    Session例子

     Session["UserName"] = txtUser.Text;
    if (Session["UserName"] != null)
    {   
        lblWelcome.Text = "Welcome : " + Session["UserName"];
    }
    else
    {
     
    }


    我们也能存储其他对象,下面的例子展示了如何存储一个DataSet到Session里

    //Storing dataset on Session
    Session["DataSet"] = _objDataSet;
    下面的代码展示了如何从Session内读取DataSet

    //Check weather session variable null or not
    if (Session["DataSet"] != null)
    {
        //Retrieving UserName from Session
        DataSet _MyDs = (DataSet)Session["DataSet"];
    }
    else
    {
        //Do Something else
    }
  • 相关阅读:
    求1977!
    三进制小数
    回文数C语言
    JAVA知识点必看
    servlet HttpServletRequest
    为什么web工程要输入localhost或者是127.0.0.1
    service $sce or ng-bind-html
    jQuery的deferred对象详解
    理解promise
    理解Angular中的$apply()以及$digest()
  • 原文地址:https://www.cnblogs.com/momjs/p/6743959.html
Copyright © 2011-2022 走看看