国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JavaScript 刪除 ASP.NET 設(shè)置的多值 Cookie 的方法

2019-11-17 01:57:35
字體:
供稿:網(wǎng)友

javaScript 刪除 asp.net 設(shè)置的多值 Cookie 的方法

需要注意HttpOnly,Path等屬性。完整的測試代碼:

ASPX 代碼<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">

PRotected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { HttpCookie Cookie = new HttpCookie("user"); Cookie.Values.Add("name", "mxh"); Cookie.Values.Add("id", "net_lover"); Cookie.Expires = DateTime.Now.AddDays(1); Cookie.HttpOnly = false; Cookie.Path = "/"; Response.Cookies.Add(Cookie); } }

protected void Button1_Click(object sender, EventArgs e) { if (Request.Cookies["user"] == null) { Response.Write("已經(jīng)刪除"); } else { Response.Write("Cookie值: " + Request.Cookies["user"]["name"]); }

}</script><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>dotnet.aspx.cc Cookie 測試</title> <script type="text/Javascript"> function deleteCookie() { var expires = new Date(); expires.setUTCFullYear(expires.getUTCFullYear() - 1); document.cookie = "user=name=&id=; expires=" + expires.toUTCString() + "; path=/"; } </script></head><body> <form id="form1" runat="server"> <input type="button" value="刪除" onclick="deleteCookie()" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="查看Cookie" /> </form></body></html>

作者:孟憲會(huì)


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 肃南| 汤原县| 贵港市| 仙游县| 利辛县| 衡东县| 临夏县| 鄂托克前旗| 盐津县| 衡阳县| 尼勒克县| 岑巩县| 乌兰县| 山东省| 根河市| 漠河县| 农安县| 股票| 犍为县| 南岸区| 鄂伦春自治旗| 曲阜市| 新野县| 芮城县| 齐河县| 濉溪县| 福清市| 密山市| 伊金霍洛旗| 根河市| 大田县| 洪湖市| 若尔盖县| 灵石县| 邯郸县| 漠河县| 兴文县| 岢岚县| 荥阳市| 建宁县| 修文县|