首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-04-09 
谁帮我看看这个代码哪错了?在线等。。急啊。Label1.Text (Session[userInfo] as UserInfo).UserName +

谁帮我看看这个代码哪错了?在线等。。急啊。
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.

热点排行