Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6059167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:40:49+00:00 2026-05-23T08:40:49+00:00

I am using popular jquery Cookie plugin https://github.com/carhartl/jquery-cookie Wonder how to set and read

  • 0

I am using popular jquery Cookie plugin https://github.com/carhartl/jquery-cookie
Wonder how to set and read a cookie with multiple values? Or maybe it’s possible to add/remove values for that cookie?

$.cookie(“MyTestCookie”, email, { expires: 10 });

I want to add username to the same cookie

Update: just an example in .Net Storing multiple values in cookies

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:40:49+00:00Added an answer on May 23, 2026 at 8:40 am

    If you want to set a cookie that has multiple values or “subkeys” and have them readable from .NET, you need to store the subkey as name-value pairs formatted like a querystring. You can use the jQuery.param() method to convert a Javascript object into a querystring.

    var obj = { email: 'jdoe@example.com', username: 'jdoe' };
    $.cookie("MyTestCookie", $.param(obj), { expires: 10 });
    

    Then on the server, you can access the values as:

    var email = Request.Cookies["MyTestCookie"]["email"];
    var username = Request.Cookies["MyTestCookie"]["username"];
    

    EDIT: I created a test page to show reading/writing multi-value cookies both on the server and client. http://www.systemex.net/Cookies/

    NOTES:

    • You need to take care of escaping and unescaping the subkeys. This way any embedded = and & are handled correctly
    • When reading and writing jquery cookies, use option { raw: true } so it doesn’t double escape.
    • I wrote a $.deparam function that will convert a name=value&name2=value2 string into a javascript object { name: value, name2: value2 }
    • One last thing, the jquery cookie plugin does not overwrite a cookie with the same name, it simply appends it to the current cookie collection. At this point, it would probably be better to rewrite the plugin to support subkeys and modifying existing cookies.

    Anyway hope this helps.

    Here is Default.aspx

    <h1>Get Cookie From Server:</h1>
    <ul>
    <li>Email: <%= GetCookie("MyTestCookie", "email")%></li>
    <li>Username: <%= GetCookie("MyTestCookie", "username")%></li>
    </ul>
    <h1>Get Cookie From Client:</h1>
    <ul>
    <li>Email: <span class="cookie" data-name="MyTestCookie" data-key="email" /></li>
    <li>Username: <span class="cookie" data-name="MyTestCookie" data-key="username" /></li>
    <li>Raw: <span id="raw" /></li>
    </ul>
    <h1>Set Cookie From Client:</h1>
    <ul>
    <li>Email: <input type="text" name="email" value="" /></li>
    <li>Username: <input type="text" name="username" value="" /></li>
    </ul>
    <input type="submit" value="Submit" />
    
    <script>
    
        $(function () {
            $(".cookie").each(function (index) {
                var name = $(this).data('name');
                var key = $(this).data('key');
                var cookie = $.deparam($.cookie(name, { raw: true }));
    
                $(this).html(cookie[key]);
            });
            $('#raw').text(escape($.cookie("MyTestCookie"), { raw: true }));
    
    
            $("form").submit(function () {
                var o = {};
                o.email = $('input[name=email]').val();
                o.username = $('input[name=username]').val();
                var value = $.param(o);
                var cookie = $.cookie('MyTestCookie', value, { raw: true });
                return true;
            });
        });
    
        jQuery.deparam = function (params) {
            var o = {};
            if (!params) return o;
            var a = params.split('&');
            for (var i = 0; i < a.length; i++) {
                var pair = a[i].split('=');
                o[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
            }
            return o;
        }
    
    </script>
    

    Default.aspx.cs

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            var cookie = new HttpCookie("MyTestCookie");
            cookie["email"] = HttpUtility.UrlEncode("jdoe@example.com");
            cookie["username"] = HttpUtility.UrlEncode("jdoe&123");
            Response.Cookies.Add(cookie);
        }
    }
    
    public string GetCookie(string name, string key)
    {
        var cookie = Request.Cookies[name];
        return cookie != null ? HttpUtility.UrlDecode(cookie[key]) : "";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JBoss Seam Framework, but it's seems to me isn't very popular among
Using JDeveloper , I started developing a set of web pages for a project
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
Using C#, I need a class called User that has a username, password, active

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.