C# 和 JavaScript Cookie 共享
.divRoot
{
border: dotted 1px red;
padding: 20px;
margin: 20px;
}
.divRoot h1
{
text-align: center;
color: Blue;
background-color:Gray;
}
hr
{
color: Green;
}
function addCookie(key,value) {
var expireDate = new Date(); //cookie 有效日期
expireDate.setMonth(expireDate.getMonth() + 6);
document.cookie = key+"=" + value + "; expires=" + expireDate.toGMTString(); //新增 cookie
alert("新增成功~!!");
return false;
}
function getCookie() {
if (document.cookie != "") {
document.getElementById("spCookie").innerHTML = document.cookie;
}
}
JavaScript. -> C#
JavaScript. Add Cookie:
Enter The Cookie Value:
C# Get Cookie:
The Cookie Value:
C# -> JavaScript
C# Add Cookie:
Enter The Cookie Value:
JavaScript. Get Cookie:
The Cookie Value:
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部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-621841/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- cookie跨域共享 cookie二級域名共享 前後端分離專案共享cookieCookie跨域後端
- javascript cookieJavaScriptCookie
- JavaScript 建立CookieJavaScriptCookie
- JavaScript 讀取cookieJavaScriptCookie
- JavaScript 刪除cookieJavaScriptCookie
- JavaScript cookie 跨域JavaScriptCookie跨域
- JavaScript 複習之 CookieJavaScriptCookie
- 【Javascript】——簡單cookie操作JavaScriptCookie
- JavaScript 建立與讀取cookieJavaScriptCookie
- JavaScript 是如何工作的:JavaScript 的共享傳遞和按值傳遞JavaScript
- 集合資料處理(C#、JavaScript 和 Java)C#JavaScript
- 跨域請求cookie資源共享詳解跨域Cookie
- JavaScript 寫入與讀取cookieJavaScriptCookie
- JavaScript設定cookie立即過期JavaScriptCookie
- Cookie和SessionCookieSession
- session和cookieSessionCookie
- cookie 和 sessionCookieSession
- 如何設定cookie和刪除cookieCookie
- JavaScript 設定cookie 過期時間JavaScriptCookie
- C# 爬蟲—-Cookies處理(Set-Cookie)C#爬蟲Cookie
- 【Javaweb】Cookie和SessionJavaWebCookieSession
- laravel操作session和cookieLaravelSessionCookie
- 關於Session和CookieSessionCookie
- session和cookie關係SessionCookie
- Session和Cookie機制SessionCookie
- 撩下Cookie和SessionCookieSession
- ECMA標準ECMAScript(JavaScript的一個標準)和C#JavaScriptC#
- C# + html + fetch + API + javascriptC#HTMLAPIJavaScript
- JavaScript 設定Cookie過期時間無效JavaScriptCookie
- 在 C# 和 JavaScript 之間選擇進行網頁抓取C#JavaScript網頁
- Cookie 和 Session 關係和區別CookieSession
- Django框架之Cookie和SessionDjango框架CookieSession
- 對session和cookie的理解SessionCookie
- Tomcat 中的 Session 和 CookieTomcatSessionCookie
- localStorage 與 sessionStorage / cookie 和 sessionSessionCookie
- cookie和session的區別CookieSession
- 聊一聊session和cookieSessionCookie
- nodeJS之Cookie和Session(一)NodeJSCookieSession
- 深入分析Session和CookieSessionCookie