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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:49:05+00:00 2026-05-14T00:49:05+00:00

Currently my website is based around MVC and the Entity Framework running against a

  • 0

Currently my website is based around MVC and the Entity Framework running against a SQL Server 2005 database. So far, it has all been running very smoothly, and I really enjoy MVC and its slimmer more concise code (and no huge viewstates or soul destroying postbacks ;))

Recently I was working on upgrading the site to use a simple forum system, and this is where I started running into problems. When I was testing the site using two different browsers, if I created or replied to a post in one browser, the other browser couldn’t see the post.

At the moment, each visitor to the site gets their own copy of the entity model, which I store in their session data. Obviously this is the problem as updates to one model aren’t getting carried to the other.

As a test, I tried storing a single copy of the model which all visitors would access by assigning the model to a static variable. This worked, and both browsers could see each others modifications. However, it had its side effects. For example, if I fired up both browsers at the same time and the model was initialized, one browser would crash, and the other would work fine, despite me using a locking object so in theory one of them should have been delayed until the model was ready (of course I could have implemented this wrong ;)). Also, originally this site did use one model for all visitors and when it was live, it frequently shut down – killing the IIS application pool while it did. Now I’m not sure if this was related, but I don’t really want to reintroduce whatever bug I had that caused this shut down.

So, my question is a simple one really – what is the best way of either using the same model for all website users so they all see updates, or if they do have separate copies (which I imagine will have a performance impact in time) how can the models detect changes in the database and update themselves according.

Thanks in advance for any advice!

Regards;
Richard Moss

  • 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-14T00:49:05+00:00Added an answer on May 14, 2026 at 12:49 am

    Get required data from the database on each request. Let web and/or ASP.Net caching do its job instead of putting data in session state.

    Cache invalidation, on timeout or by directly invalidation through code, can be done whenever new data are submitted to the database.

    Some more clarification: when I say “get required data…on each request” it is based in the fact that from a resource management perspective it is more cost-effective to get data from the database when you need it. Storing a copy of the forum data in each users session state will quickly drain your server of memory (depending on the number of users and size of the data of course). Also, as you have experienced yourself, trying to keep those copies synchronized with new changes becomes very hard. Again, going to the database whenever you need data solves these synchronization issues too.

    So to answer your “what is the best way…” question: don’t store the model at all. Datacontext and model should only live as long as needed for one page request.

    Now, I mentioned caching because that would probably be why you put data in session state in the first place. EF does not do caching. What I suggest is look at the ASP.Net caching features. This is caching at the page and html level which is much more resource efficient.

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

Sidebar

Related Questions

Im currently making a very simple WebApp on a Website using ASP.NET Framework using
How can I implement following in ASP.NET MVC application: user opens intranet website user
I've got an existing website (based on .net 1.1), that calls web-services (based on
HI I'm building a php based website and wanted to know if there any
I have a classifieds website, where anyone (no need for login currently) can post
I am going to use Flask micro-framework (based on Werkzeug , and I'll be
I'm developing the CSS file for the mobile version of the website my group
Question: Is there any way to track how many website visitors are leaving your
All, I am building a small, non-commercial consumer website. During the user registry, I
Let me just start off by saying I am very much a beginner and

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.