首页 > 解决方案 > 关闭应用程序后延长 Cookie 的生命周期

问题描述

我在 asp.net 中有一个应用程序,我在其中创建了一个具有定义时间的 cookie,这个时间是在我实时执行应用程序时完成的

我想看看我应该如何定义 cookie,以便即使应用程序没有运行,它也能持续实现的时间

我需要帮助来实现当应用程序稍后运行并且浏览器中存在该 cookie 时,根据 cookie 的值加载默认数据

我已经从页面加载方法 pointB.aspx.cs 中定义了 cookie

应用程序关闭并再次运行后,使用 pointB.aspx.cs 的 page_load 中的 cookie

点A.aspx.cs

     namespace Test
 {
   public partial class _Default : Page
  {
   
    protected void Page_Load(object sender, EventArgs e)
    {
       
     HttpCookie apple = new HttpCookie("apple", "0");
     apple.Expires = DateTime.Now.AddMinutes(30);
     Response.Cookies.Add(apple);
     
     Response.Write("<script>alert('Apple cookie has been Created');</script>");
    
    }
}

 }

pointB.aspx.cs

   namespace Test
   {
       public partial class _Default : Page
  {
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["apple"]flagUserType != null)
            {
                Response.Write("<script>alert('Apple can be eaten');</script>");
                Response.Write("<script>alert('"+ Request.Cookies["apple"].Value.ToString() +"');</script>");
            }
    
    }
}

}

请帮忙 :)

标签: asp.netvalidationcookieshttpcontextpageload

解决方案


推荐阅读