Is it possible to persist cookies between visual studio debug sessions

前端 未结 3 2003
忘掉有多难
忘掉有多难 2021-01-05 00:46

I have an authentication cookie that gets set after I hit a login screen in my local environment. That cookie has been set to be persistent and has been given a timeout peri

3条回答
  •  失恋的感觉
    2021-01-05 01:22

    Let’s have a quick look how to make cookies as persistent

        //Creting a Cookie Object
     HttpCookie _userInfoCookies = new HttpCookie("UserInfo");
    
    //Setting values inside it
     _userInfoCookies["UserName"] = "Abhijit";
     _userInfoCookies["UserColor"] = "Red";
     _userInfoCookies["Expire"] = "5 Days";
    
     //Adding Expire Time of cookies
      _userInfoCookies.Expires = DateTime.Now.AddDays(5);
    
     //Adding cookies to current web response
     Response.Cookies.Add(_userInfoCookies);
    

    Now once you have set with the Cookies expires time , it will be stored in hard drive until expires or user manually delete or clear all the cookies. If you want your cookies need to be expires before the expiration time that you have mentioned earlier, you just need to override the cookies information.

    HttpCookie _userInfoCookies = new HttpCookie("UserInfo");
       //Adding Expire Time of cookies before existing cookies time
       _userInfoCookies.Expires = DateTime.Now.AddDays(-1);
       //Adding cookies to current web response
       Response.Cookies.Add(_userInfoCookies);
    

    So Just Work on Expiration. and take a look at This

提交回复
热议问题