网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 设计资源 > .Net编程 > 正文

记录Cookie集合并读取,可用于产品的最近访问控制

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

using System;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text.RegularExpressions;
using System.Collections;



public partial class _Default : System.Web.UI.Page  
{
    SQLHelper.SQLHelp sh = new SQLHelper.SQLHelp();
    string sqlString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
         if (Request.Cookies["username"] == null)
                {
                    HttpCookie myCookie = new HttpCookie("username");
                    myCookie.Values.Add("prodid", "");
                    myCookie.Expires = DateTime.Now.AddDays(1);
                    Response.Cookies.Add(myCookie);
                }

    }

    /////
    ///// 给网址加http://
    /////
    /////"_Cont">
    /////
    //   public static string String_UrlAddLink(string _Cont)  
    //    {  
    //        string StrRegex = @"(http://)?([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?";  
    //        Regex R = new Regex(StrRegex, RegexOptions.IgnoreCase);  
    //        _Cont = Regex.Replace(_Cont, StrRegex, "$0");  
    //        _Cont = _Cont.Replace("http://http://", "http://");  
    //        return _Cont;  
    //    }

       public void addcookie(string cookievalue)
       {
            
            HttpCookie cookie = new HttpCookie("username");
            if (Request.Cookies["username"].Values["prodid"] != "")
           {
                string myvalue = "";
                myvalue = Request.Cookies["username"].Values["prodid"].ToString();
                myvalue = cookievalue + "," + myvalue;
                cookie.Values.Add("prodid", myvalue);
                cookie.Expires = DateTime.Now.AddDays(1);
                Response.Cookies.Add(cookie);
            }

            else
           {
                cookie.Values.Add("prodid", cookievalue);
                cookie.Expires = DateTime.Now.AddDays(1);
                Response.Cookies.Add(cookie);
            }

        }


      public string playcookie()
       {
            int num = 0;
            string myvalue = "";
            myvalue = Request.Cookies["username"].Values["prodid"].ToString();
            string resultvalue=string.Empty;
            if (myvalue != "")
            {
                Char spitchar = new Char { Convert.ToChar(",") };
                string cookievalue;
                cookievalue = myvalue.Split(spitchar);
                if (cookievalue.Length <= 3)
                {
                    num = cookievalue.Length;
                }

                else
                {
                    num = 3;
                }

                for (int i = 0; i < num; i++)
                {
                    resultvalue += cookievalue[i].ToString()+";";
                }

                Label1.Text = resultvalue;
                
            }

            return resultvalue;
        }

       protected void btnUrl_Click(object sender, EventArgs e)
       {
           addcookie("1");
       }

       protected void Button1_Click(object sender, EventArgs e)
       {
           addcookie("2");
       }

       protected void Button2_Click(object sender, EventArgs e)
       {
           addcookie("3");
       }

       protected void Button3_Click(object sender, EventArgs e)
       {
           string anySqlStr = playcookie().Split('';'');
           DataTable dtNew = new DataTable();
           DataColumn dc1 = new DataColumn("cid");
           DataColumn dc2 = new DataColumn("cName");
           dtNew.Columns.Add(dc1);
           dtNew.Columns.Add(dc2);
           DataRow drNew;
           foreach (string ss in anySqlStr)
           {
               drNew = dtNew.NewRow();
               if (ss != "")
               {
                   sqlString = "select * from city where cid=" + ss;
                   DataTable dt = sh.RunSQLReturnDs(sqlString).Tables[0];
                   drNew["cid"] = dt.Rows[0]["cid"].ToString();
                   drNew["cName"] = dt.Rows[0]["cName"].ToString();
                   dtNew.Rows.Add(drNew);
               }

               //Response.Write(ss+"");
           }

           GridView1.DataSource = dtNew;
           GridView1.DataBind();
       }

}

 

  • 上一篇资讯: 获取天气信息
  • 下一篇资讯: gv前3条数据显示new
  • 设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
    版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师