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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:26:00+00:00 2026-06-03T09:26:00+00:00

Is it ok to get/set session variable inside a private/public property? private List<FileAttachment> fileAttachments;

  • 0

Is it ok to get/set session variable inside a private/public property?

private List<FileAttachment> fileAttachments;
public List<FileAttachment> FileAttachments
{
    get
    {
        if (Session["key"] != null)
        {
            fileAttachments = (List<FileAttachment>)Session["key"];
        }
        return fileAttachments;
    }
    set
    {
        fileAttachments = value;
        Session["key"] = fileAttachments;
    }
}

The goal here is I’d like for the container class (of this user control the property is in) to be able to set the List<T> depending on what entity and show existing attachments that’s stored in the database.

  • 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-06-03T09:26:01+00:00Added an answer on June 3, 2026 at 9:26 am

    That’s not very safe; List<T> is not thread-safe.

    You can never modify the list after assigning it to the property, since some other request thread might be reading it.

    Therefore, you should make it a ReadOnlyCollection<T> rather than List<T>.
    (and make sure your FileAttachment class is immutable or thread-safe)


    Other than that, it depends where the property is.
    If it’s on a control or page, it’s fine.

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

Sidebar

Related Questions

I cannot get/set a static variable inside a method. How can I do it?
I have an aspx page (page1.aspx) where I set a Session variable and then
I'm currently learning Sinatra, and I can't seem to set a session variable to
Using get/set seems to be a common practice in Java (for various reasons), but
How do you set/get the values of attributes of t given by x ?
I need to get one set of rows (it will be more than 70k
I need to be able to get and set the textbox's text, but I
I have a script to get and set user's Windows environment variables on other
I've been trying to get django set up so I can start learning it.
I'm looking for a way to get and set those oddball chunks in a

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.