How to set multiple key-value pairs to one cookie?

前端 未结 2 1557
挽巷
挽巷 2020-12-09 10:20

I am using this line to set multiple key-value pair at once to one cookie

document.cookie=\"username=John Smith; test1=ew; expires=Thu, 18 Dec 2013 12:00:00          


        
2条回答
  •  青春惊慌失措
    2020-12-09 10:37

    Actually i think it would be better to use
    document.cookie = "myCookie=foo='bar'&baz='poo'; here is the rest of cookie specifications if you like..."
    as far as i know, it also is compatible with Asp and Asp.Mvc on server side:
    string foo=Request.Cookies["myCookie"]["foo"]

提交回复
热议问题