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

  • SEARCH
  • Home
  • 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 4025850
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:53:52+00:00 2026-05-20T10:53:52+00:00

So, I am working on a demo web dashboard. Previously, I had been using

  • 0

So, I am working on a demo web dashboard. Previously, I had been using Session to store settings about the dashboard, but I would like to move it to a more persistent means of saving settings.

It seems to me that using cookies would be my best bet. I’m not entirely positive I have the time to work everything out for writing to/from a database properly.

That being said, I might be in over my head on some assumptions I had made about the similarities between Session and Cookies.

Currently, I have some code like this:

public Dictionary<string, RadPageViewSetting> PageViewStates
    {
        get
        {
            Dictionary<string, RadPageViewSetting> _pageViewStates = (Dictionary<string, RadPageViewSetting>)Session["PageViewStates"];
            if (object.Equals(_pageViewStates, null))
            {
                _pageViewStates = new Dictionary<string, RadPageViewSetting>();
                Session["PageViewStates"] = _pageViewStates;
            }

            return _pageViewStates;
        }
        set
        {
            Session["PageViewStates"] = value;
        }
    }

where RadPageViewSetting is a class with some properties in it which I am recording.

Is this functionality possible with cookies? If not, where should I be looking to persist my data through browser-closes?

EDIT: I am going to use http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx to help me serialize the dictionary and then go about serializing my own custom data hypers (RadPageViewSetting).

EDIT: Here’s my untested solution. Could someone take a look at this real quick and let me know if it looks incorrect?

        public SerializableDictionary<string, RadPageViewSetting> PageViewStates
    {
        get
        {
            SerializableDictionary<string, RadPageViewSetting> _pageViewStates = new SerializableDictionary<string,RadPageViewSetting>();
            HttpCookie cookie = HttpContext.Current.Response.Cookies["PageViewStates"]; //If the named cookie does not exist, this method creates a new cookie with that name.

            if (object.Equals(cookie, null))
            {
                cookie = new HttpCookie("PageViewStates");
                cookie.Expires = DateTime.Now.AddYears(100);
                cookie.Value = null;
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
            else if( cookie.Value != null )
            {
                MemoryStream stream = new MemoryStream();
                StreamWriter writer = new StreamWriter(stream);
                writer.Write(cookie.Value);
                XmlSerializer serializer = new XmlSerializer(_pageViewStates.GetType());
                _pageViewStates = serializer.Deserialize(stream) as SerializableDictionary<string, RadPageViewSetting>;
                HttpContext.Current.Response.Cookies.Set(cookie);
            }

            return _pageViewStates;
        }
        set
        {
            XmlSerializer serializer = new XmlSerializer(value.GetType());
            MemoryStream stream = new MemoryStream();
            serializer.Serialize(stream, value);
            StreamReader reader = new StreamReader(stream);
            HttpContext.Current.Response.Cookies["PageViewStates"].Value = reader.ReadToEnd();
        }
    }
  • 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-20T10:53:52+00:00Added an answer on May 20, 2026 at 10:53 am

    Simple use Response.Cookies instead of Session.

    Basically in a nutshell from MSDN

    
    
    
    Response.Cookies["userName"].Value = "patrick";
    Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);
    
    HttpCookie aCookie = new HttpCookie("lastVisit");
    aCookie.Value = DateTime.Now.ToString();
    aCookie.Expires = DateTime.Now.AddDays(1);
    Response.Cookies.Add(aCookie);
    

    You should be able to store what ever you like in the cookie as long as you can serialize it into a string. As cookies are plain text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like a working example, that uses a asp.net session state server, to
I am working on a demo for a client of what's possible with GWT-Ext
I'm working on a demo that makes use of Spring.NET IoC capability in ASP.NET
I am working on an Azure demo to run Powershell in a worker role.
I am working on a web application, whose mock-up page can now be found
I am working a resonably sized java project that needs some sort of web
I am developing a web app (using rails) that I will be launching within
Why isn't this script working? $(function() { var isbn = $('input').val(); $('button').click(function() { $(#data).html('<iframe
i have developed an web application[ERP FOR A SCHOOL].i have given the build for
I need to determine whether a selected UIColor (picked by the user) is dark

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.