2
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetLeft.Value = invited.GetInviteCountByWeb().ToString();
HttpCookie oldCookie = Request.Cookies["Time"];
if (oldCookie != null)
{
if (DateTime.Now.ToString("yyyy-MM-dd") == Convert.ToDateTime(oldCookie.Values["GetTime"]).ToString("yyyy-MM-dd"))
{
this.IsGet.Value = "false";
}
else
{
HttpCookie newCookie = new HttpCookie("Time");
newCookie.Values.Add("GetTime", DateTime.Now.Date.ToString("yyyy-MM-dd"));
newCookie.Expires = DateTime.Now.AddHours(24.0);
Response.Cookies.Add(newCookie);
}
}
}
}
,但它不工作时,oldcookie为空时,关闭浏览器每次.. 所以我怎样才能设置按钮点击,每天一次?C#按钮,点击每日一次
你想做什么?一般来说,您不能依靠浏览器来保持持久性cookie,因为您可以告诉浏览器在浏览器关闭时删除它们。 – Paolo
为什么使用可空属性'this.IsGet'?什么类封装了这个方法? –
我加了ASP.NET标签来澄清。无论如何,这是一个不好的方法,你必须将信息服务器端(DB想到的)存储在cookie中。如果用户在每次关闭浏览器时自动清除cookie,该怎么办? – Alex