none
System.Net.Cookie. How to set multiple key-value (name-value) RRS feed

  • Question

  • Hello.

    Is it possible to set multiply name-value pairs like in a HttpCookie. For now I see only one name and value. Should I manually concatinate, like

    cookie.Value += ";name1=value1"  

    And if so why there is no API to setup name-value pairs.

    Thanks in advance.

    Thursday, August 29, 2013 11:44 AM

All replies

  • Hi,

    Yes, it is possible.

    For more information, please try to refer to this following article:

    #Get and Set Multiple values in a single Cookie in ASP.NET:
    http://www.c-sharpcorner.com/Blogs/8809/get-and-set-multiple-values-in-a-single-cookie-in-Asp-Net.aspx .

    And this forums is the WCF Forums. It will be better if you post your question in asp.net fourm to get more help.

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, August 30, 2013 3:43 AM
    Moderator
  • Hi Amy!

    Your answer is too confusing. First of all, I'm using Cookie class from System.Net namespace which I think is related to this forum, namely Networking.

    You've pointed me to  the HttpCookie class, but I use System.Net.Cookie which are obviously different and I'm not using ASP,net, I'm using WCF REST Service.

    And it seems that for my scenario there is no way to use HttpCookie...

    Thanks in advance.

    Friday, August 30, 2013 9:07 AM
  • Hi,

    I am very sorry, I thought you want to implemet this using httpcookie, I did not see that you are using the System.Net.Cookie.

    I am sorry again, it is my fault.

    If I do not misunderstand your iead, cookies can be set on Set-Cookie.

    Please try to refer to these two similar threads:
    http://stackoverflow.com/questions/2444022/how-to-add-multiple-cookies-to-response-in-wcf-rest-service .
    http://stackoverflow.com/questions/5144354/issue-with-adding-multiple-cookies-to-response-in-wcf-service .

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, August 30, 2013 9:43 AM
    Moderator
  • Well, it is still not exactly what I want:

    for now (see my example above and solutions from SO) my cookie looks like (on chrome dev tools):

    name           value

    userId          1,name1=value1,name2=value2

    What I want, is to come up with this::

    name           value

    userId           1

    name1          value1

    name2          value2

    Is it possible in my case?

    • Edited by Sharov A Friday, August 30, 2013 12:46 PM
    Friday, August 30, 2013 12:44 PM
  • Anyone?
    Friday, September 6, 2013 9:28 AM