cookie编程

上一篇 / 下一篇  2010-09-18 17:24:39 / 个人分类:C#


B^ jx3v#g0

;O)~%qa,U-\*Q0
51Testing软件测试网)wNj%a Vjt4I
code:
51Testing软件测试网h _o+H2b5q&V
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

P'r*uF-o|Z0
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie hc = Request.Cookies["UserCookie"];

8aeD H/K|0
        if (hc == null)
        {
            hc = new HttpCookie("UserCookie");

PL!F {mI b0
            hc.Value = "xxx";
51Testing软件测试网txh L qh}
            DateTime now = DateTime.Now;
51Testing软件测试网_u fn8EZ.u6x
            TimeSpan ts = new TimeSpan(1, 1, 1);

~Rd(xC"yzN*O0
            hc.Expires = now + ts;

@.uR-}`?f0
            hc["Username"] = "kaka";
51Testing软件测试网*g)\/t5_t%g7T/|;QLq|
            Response.Cookies.Add(hc);

8bT"B.Y c0
            Response.Write("cookie is already added!");
51Testing软件测试网t5I:Z9gld(kVw2[
        }
        else
        {
            Response.Write(hc.Values["Username"].ToString());
            
        }
    }
}

D"n?&C1^T7Z)l0

TAG:

 

评分:0

我来说两句

Open Toolbar