<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cookie.aspx.cs" Inherits="cookie" %>
cookie.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class cookie : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnGetCookie_Click(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies.Get("userName");
if (cookie != null)
{
lblCookie.Text = cookie.Value;
}
else
{
lblCookie.Text = "NULL";
}
}
protected void btnAddCookie_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("SharpCookie");
cookie.Value = txtCookie.Text;
Response.Cookies.Add(cookie);
txtCookie.Text = string.Empty;
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-621841/ ,如需转载,请注明出处,否则将追究法律责任。