C# Cookie跨域实例
生活随笔
收集整理的這篇文章主要介紹了
C# Cookie跨域实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1)站點1,創建Cookie
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;namespace WebApplication1 {public partial class Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){//設置CookieHttpCookie myCookie = new HttpCookie("MyCook");//初使化并設置Cookie的名稱DateTime dt = DateTime.Now;TimeSpan ts = new TimeSpan(0, 0, 1, 0, 0);//過期時間為1分鐘myCookie.Expires = dt.Add(ts);//設置過期時間myCookie.Values.Add("LoginName", "Admin");Response.AppendCookie(myCookie);}}/// <summary>/// 獲取Cookie/// </summary>/// <param name="sender"></param>/// <param name="e"></param>protected void btnTestCookie_Click(object sender, EventArgs e){HttpCookie myCookie = HttpContext.Current.Request.Cookies["MyCook"];if (myCookie != null){string LoginName = myCookie["LoginName"];}}} }2)站點2,跨域獲取Cookie using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;namespace WebApplication2 {public partial class Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){HttpCookie myCookie = HttpContext.Current.Request.Cookies["MyCook"];if (myCookie != null){string LoginName = myCookie["LoginName"];}}} }
總結
以上是生活随笔為你收集整理的C# Cookie跨域实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 代理服务器CCProxy基本设置
- 下一篇: java removeat,在c#中 R