读书人

哪位高手帮小弟我看看这个代码哪错了?

发布时间: 2012-04-09 13:41:24 作者: rapoo

谁帮我看看这个代码哪错了?在线等。。急啊。
Label1.Text = (Session["userInfo"] as UserInfo).UserName + "欢迎您!";
if (Request.Cookies["name"] == null)
{
HttpCookie hc = new HttpCookie("name", (Session["userInfo"] as UserInfo).UserName);
hc.Expires = DateTime.Now.AddMonths(1);
HttpCookie tm = new HttpCookie("time", DateTime.Now.ToString());
tm.Expires = DateTime.Now.AddMonths(1);
HttpCookie ct = new HttpCookie("count", "1");
ct.Expires = DateTime.Now.AddMonths(1);
Response.Cookies.Add(hc);
Response.Cookies.Add(ct);
Response.Cookies.Add(tm);
}
else
{
Response.Cookies["time"].Value = DateTime.Now.ToString();
Response.Cookies["count"].Value = (int.Parse(Request.Cookies["count"].Value) + 1).ToString();
}

关闭浏览器在打开 count Cookie的值为null,别的都有值

[解决办法]
设定
hc.Domain="xxx.com";//域名
tm.Domain="xxx.com";//域名
ct.Domain="xxx.com";//域名
[解决办法]

C# code
 else            {                Response.Cookies["time"].Value = DateTime.Now.ToString();                HttpCookie ct = new HttpCookie("count", (int.Parse(Request.Cookies["count"].Value) + 1).ToString());                ct.Expires = DateTime.Now.AddMonths(1);                Response.Cookies.Add(ct);            }
[解决办法]
你想干嘛??
直接说吧
[解决办法]
Label1.Text = (Session["userInfo"] as UserInfo).UserName + "欢迎您!";
if (Request.Cookies["name"] == null)
{
HttpCookie hc = new HttpCookie("name", (Session["userInfo"] as UserInfo).UserName);
hc.Expires = DateTime.Now.AddMonths(1);
HttpCookie tm = new HttpCookie("time", DateTime.Now.ToString());
tm.Expires = DateTime.Now.AddMonths(1);
HttpCookie ct = new HttpCookie("count", "1");
ct.Expires = DateTime.Now.AddMonths(1);
hc.Domain="xxx.com";//域名
tm.Domain="xxx.com";//域名
ct.Domain="xxx.com";//域名
Response.Cookies.Add(hc);
Response.Cookies.Add(ct);
Response.Cookies.Add(tm);
}
else
{
Response.Cookies["time"].Value = DateTime.Now.ToString();
Response.Cookies["count"].Value = (int.Parse(Request.Cookies["count"].Value) + 1).ToString();
}
本地就写localhost,传到网上就改网站的域名,不要http://www.

读书人网 >asp.net

热点推荐