How to handle multi value cookies in ASP.NET Core?

后端 未结 2 1478
太阳男子
太阳男子 2021-01-02 10:16

In the full .NET framework we have support for multi value cookies. e.g. a cookie could have multiple values:

HttpCookie aCookie = new HttpCookie("userIn         


        
2条回答
  •  执笔经年
    2021-01-02 11:21

    CookieManager wrapper allows you to play with objects. you can easily read/write object in asp.net core. it offers you to encrypt the cookie value to secure your data

    check out: https://github.com/nemi-chand/CookieManager

    Create your poco/object what you want to store in cookie.

    public class MyCookie
    {
      public string Id { get; set; }
    
      public DateTime Date { get; set; }
    
      public string Indentifier { get; set; }
    }
    

    fill the object values

    MyCookie cooObj= new MyCookie()
    {
      Id = Guid.NewGuid().ToString(),
      Indentifier = "valueasgrsdgdf66514sdfgsd51d65s31g5dsg1rs5dg",
      Date = DateTime.Now
    };
    

    set the myCookie object

    _cookieManager.Set("Key", cooObj, 60);
    

    get the myCookie object

    MyCookie objFromCookie = _cookieManager.Get("Key");
    

提交回复
热议问题