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 6666667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:51:09+00:00 2026-05-26T02:51:09+00:00

I am working in a project in ASP.NET. I want to cache the username

  • 0

I am working in a project in ASP.NET.

I want to cache the username for the first time when the user logs in. E.g: If the current user is logged in and visiting a particular page for the first time, there will be a popup window display, otherwise nothing happens.

The username should be stored in the client browser and remain valid until the user closes the browser.

My question is, what is the best approach of doing this?

Any limitations if I am using ASP.Net Cache to store the username?
For example:

Cache["myCache"] = username;

and remove the item from the cache when page loads for the first time.

if (!Page.IsPostBack)
{
     Cache.Remove("myCache");
}

This is open for any comments. Thank you in advance.

  • 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-26T02:51:10+00:00Added an answer on May 26, 2026 at 2:51 am

    Use a HttpCookie and set the expiration as needed:

    If you do not set the cookie’s expiration, the cookie is created but
    it is not stored on the user’s hard disk. Instead, the cookie is
    maintained as part of the user’s session information. When the user
    closes the browser, the cookie is discarded.

    ASP.NET Cookies Overview

    //write
    HttpCookie myCookie = new HttpCookie("UserSettings");
    myCookie["Font"] = "Arial";
    myCookie["Color"] = "Blue";
    //myCookie.Expires = DateTime.Now.AddDays(1d);
    Response.Cookies.Add(myCookie);
    
    //read
    if (Request.Cookies["UserSettings"] != null)
    {
        string userSettings;
        if (Request.Cookies["UserSettings"]["Font"] != null)
        { userSettings = Request.Cookies["UserSettings"]["Font"]; }
    }
    

    How to: Write a Cookie

    How to: Read a Cookie

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

Sidebar

Related Questions

I'm working on an ASP.NET project for a school. In one area I want
The ASP.NET web app project I'm currently working on is getting slower over time
I am working on asp.net project and each time i need to use jquery
I am working on project using asp.net mvc3 C# . I want to change
Hi I am working on a Hotel Reservation Project in ASP.NET. I want to
I'm working on asp.net project using VS2010 . I want to share my project
I'm working on an ASP.NET project which generates screen shots. I want to use
I am working an Asp.net project, I am loading two user controls into another
I'm working with ASP.NET project where the user can upload files to the server.
Hi I am working on a Hotel Reservation Project in ASP.NET. I want to

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.