Storing multiple values in cookies

后端 未结 3 510
盖世英雄少女心
盖世英雄少女心 2020-12-02 14:41

I have very large website which uses a lot of cookies. There are approx. 14 different cookies are there. I have different cookies for each item. When a user surfs the site t

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 15:06

    Matthew beat me to it, but yes, see the ASP.NET Cookies Overview...

    To write and read a single cookie with multiple key/values, it would look something like this:

    HttpCookie cookie = new HttpCookie("mybigcookie");
    cookie.Values.Add("name", name);
    cookie.Values.Add("address", address);
    
    //get the values out
    string name = Request.Cookies["mybigcookie"]["name"];
    string address = Request.Cookies["mybigcookie"]["address"];
    

提交回复
热议问题