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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:26:55+00:00 2026-05-27T14:26:55+00:00

I am currently using ASP.Net state server to store session data in my application.

  • 0

I am currently using ASP.Net state server to store session data in my application.

As a workaround to a larger problem with sessions (don’t ask), I need to remove a set of keys that contain a certain string from session, but I don’t know the exact keys.

I want to do something like the code below. Since the session data is out of process, my concern is that by doing this I am loading the entirety of the session data into the ASP.Net worker process. This is a problem, because the current application puts too much data in session (the longer term problem we are trying to solve).

Does anyone know how the session gets accessed under the hood? Is there a way to iterate over session keys without loading the session into memory?

//does this line cause the session to be loaded back into the WP?
var session = HttpContext.Current.Session;

if (session != null)
{
    //what about this line?
    var keysToRemove = session.Keys.Cast<object>().
        Where(key => key.ToString().Contains(MYKEY)).ToList();
    foreach (var key in keysToRemove)
    {
        session.Remove(key.ToString());
    }
}
  • 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-27T14:26:56+00:00Added an answer on May 27, 2026 at 2:26 pm

    Whole session is always loaded to memory on user’s request for built in providers. It is loaded before execution reaches normal page code (not lazily as you assume). The only thing you can do to prevent loading is to have module that listens to one of the early events and removes session Id from request.

    Note: session.Keys is already collection of strings, so you can remove such complicated casting.

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

Sidebar

Related Questions

I am currently building an application using ASP.NET MVC. The data entry pages are
I'm currently using an Open Session in View pattern in an ASP.NET WebForms application
I am currently using asp.NET MVC to build a Content Management System parts of
I am currently using ASP.NET MVC 2.0 RC2, having recently moved from version 1.0.
I am currently using ASP.NET MVC1 in my project but now i am planing
Im currently using vs2008 with asp.net mvc framework for web development. Im missing a
I have a ASP.Net 2.0 website that is currently using a custom MembershipProvider and
I'm currently using Subversion to manage my ASP.NET website. I'm finding that whenever I
I just found out about superfish and currently using it on an asp.net. The
I am currently creating an e-commerce site using C# ASP.NET MVC and have just

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.