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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:28:03+00:00 2026-05-11T18:28:03+00:00

I have an application that was written in vanilla ASP.NET that I would like

  • 0

I have an application that was written in vanilla ASP.NET that I would like to port over to ASP.NET MVC.

I, however, am confused about the right place to persist objects. I need to persist for a couple reasons:

  1. I would like all to have a single database connection, wrapped in a “repository” or “manager” style object.
  2. Each user has a user object that needs to be saved on a per-session basis.

Normally, I would say that #1 would be saved as a static item in the Globals.asax that can be hit using Global.Repository or similar.

And I would normally say that #2 should be a property with a session backing store somewhere in the base class of the pages.

Now the reason I am confused is that I have heard that sessions have changed in MVC, and the Global.asax no longer holds the same class. Also, the concept of pages has been removed, so adding a property to the base class of a controller seems… wrong.

What say yall?

  • 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-11T18:28:03+00:00Added an answer on May 11, 2026 at 6:28 pm

    Your database would go in a base class for your controllers. This base class should extend Controller, and all your controllers should extend the base class. Here’s a little example:

    public class BaseController : Controller
    {
        private AuthServices _auth;
        private LogHelper _log;
        private Repository _repository;
    
        /// <summary>
        /// <see cref="AuthServices"/>
        /// </summary>
        protected AuthServices Authorization
        {
            get { return _auth ?? (_auth = new AuthServices()); }
        }
    
        /// <summary>
        /// <see cref="LogHelper"/>
        /// </summary>
        protected LogHelper Log
        {
            get { return _log ?? (_log = new LogHelper()); }
        }
    
        /// <summary>
        /// <see cref="Repository"/>
        /// </summary>
        protected Repository Repository
        {
            get { return _repository ?? (_repository = new Repository()); }
        }
    }
    

    Notice the lazy instantiation. That allows me to sneak in before running tests and set my private fields with mocks.

    As for the session, your User object can still be saved in the session just as in a traditional ASP.NET application. Almost everything is still around (Response, Cache, Session, etc), but some of them have been wrapped with classes from System.Web.Abstractions so that they can be mocked for testing. They all still behave the same way, though you shouldn’t use some of them in their traditional role (e.g., don’t Response.Redirect, return an ActionResult such as RedirectToRouteResult that performs your redirection).

    As for the reasoning behind your questions….

    Don’t stress on a single db connection. Depending on your implementation it may even be a bad idea, as requests may step on each other. Just open your connex, use it, and dispose/close it when done.

    Also, one of the biggest changes that MVC brings is the rejection of the stateful model that traditional ASP.NET attempted to bring to web development. All that framework and viewstate doesn’t exist anymore (pay no attention to the man behind the curtain). The less state you hold onto the less complex and more robust your web application is. Try it, you might like it.

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

Sidebar

Related Questions

I have a MVC3 application that I would like to port to MVC4. I
I have to support an application that was written in .NET 1.1 many years
I have a .NET application that was written in C# and VB.NET using WinForms.
I have network application that handles about 40k msg/sec written using netty framework and
We have an application that is written in .NET 3.5. This app works on
I have a WinForms application that was written in C# .NET 3.5. This application
I have an application that is an asmx web service written in .NET 2.0
I have a web application that was originally written on .Net 1.1 Framework. I
I have an application that is written in VB.NET, using the System.Windows.Forms.Form as the
I have an application that was originally written in Borland C++ and used 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.