C#实现访客浏览历史记录(足迹)的方法连环可解也>财会知识
:cookiestringcookie记录用户浏览的ID,格式为-1-2-3-4-5-。#region 存储cookie set(key,value,days)public static bool set( string strName, string strValue, int strDay ){try{HttpCookie Cookie = new HttpCookie( strName );Cookie.Domain = GetHost(); /* 当要跨域名访问的时候,给cookie指定域名即可,xxxx */Cookie.Expires = DateTime.Now.AddDays( strDay );Cookie.Value = strValue;HttpContext.Current.Response.Cookies.Add( Cookie );return(tr ue);}catch{return(false);}}#endregion#region 读取cookie值get(key)public static string get( string strName ){HttpCookie Cookie = HttpContext.Current.Request.Cookies[strName];if ( Cookie != null ){return(Cookie.Value.ToString() );}else {return(null);}}#endregion#region 用户历史记录public static void history( string id ){varisHit= false;varhistory = ( “history”);if ( string.IsNullOrEmpty( history ) ){CookieHelper.Cookie.set( “histor y”, “-”+ id + “-”, 1 );isHit = true;}else {/* -1-2-3-4-5-6-7- */if ( history.Contains( “-”+ id + “-”) ){history = history.Replace( “-”+ id, ““);history = “-”+ id + history;}else {history = “-” + id + history;isHit= true;}Cookie.set( “history”, history );}if ( isHit ){/* 用户浏览写入数据库 */}}#endregion
厨卫吊顶吃鸡名字女生>恐怖电影片1
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论