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