Snowfun

导航

 

index.aspx

 if (!this.IsPostBack)
            {
                hdid = Convert.ToInt32(Request.QueryString["hdid"]);
                if (Request.Cookies["9gg"] != null)
                {
                    openid = Request.Cookies["9gg"]["openid"].ToString();
                }
                else
                {
                    //openid = "aaaaaaaaaaaaa";
                }}

 

getopenid.aspx.cs

public partial class getopenid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {

                string hdid = Request.QueryString["hdid"].ToString();
                string tplcurl = Tplcurl(Convert.ToInt32(hdid));
                if (Request.QueryString["openid"] != null)
                {
                    string openid = Request.QueryString["openid"].ToString();
                    
                    if (Request.Cookies["9gg"] == null)
                    {
                        //写入cookie
                        HttpCookie cookie = new HttpCookie("9gg");
                        DateTime dt = DateTime.Now;
                        TimeSpan ts = new TimeSpan(10000);//设置过期时间1天过期
                        cookie.Expires = dt.Add(ts);//设置过期时间
                        cookie.Values.Add("openid", openid);
                        System.Web.HttpContext.Current.Response.AppendCookie(cookie);
                    }
                    else
                    {
                        HttpCookie cookie = Request.Cookies["9gg"];
                        //如果cookie存在修改cookie
                        cookie.Values.Set("openid", openid);
                        Response.AppendCookie(cookie);
                    }
                    Response.Redirect("index.aspx?hdid=" + hdid);
                }
                else
                {
                    Response.Redirect(tplcurl);
                }
            }
        }}

 

posted on 2015-07-27 18:02  Snowfun  阅读(162)  评论(0)    收藏  举报