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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:01:18+00:00 2026-05-22T01:01:18+00:00

On my controller I have it inherit a MainController and there I override the

  • 0

On my controller I have it inherit a MainController and there I override the Initialize and the OnActionExecuting.

Here I see what is the URL and by that I can check what Client is it, but I learned that for every Method called, this is fired up again and again, even a simple redirectToAction will fire the Initialization of the same controller.

Is there a better technique to avoid this repetition of database call? I’m using Entity Framework, so it will take no time to call the DB as it has the result in cache already, but … just to know if there is a better technique now in MVC3 rather that host the variables in a Session Variable

sample code

public class MyController : MainController
{
    public ActionResult Index()
    {
        return View();
    }
}


public class MainController : Controller
{

   public OS_Clients currentClient { get; set; }

   protected override void Initialize(System.Web.Routing.RequestContext requestContext)
   {
        // get URL Info
        string url = requestContext.HttpContext.Request.Url.AbsoluteUri;
        string action = requestContext.RouteData.GetRequiredString("action");
        string controller = requestContext.RouteData.GetRequiredString("controller");
        object _clientUrl = requestContext.RouteData.Values["cliurl"];

        if (_clientUrl != null && _clientUrl.ToString() != "none")
        {
            // Fill up variables
            this.currrentClient = db.FindClientById(_clientUrl.ToString());
       }

        base.Initialize(requestContext);
    }

    protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        // based on client and other variables, redirect to Disable or Login Actions
        // ... more code here like:

        //  filterContext.Result = RedirectToAction("Login", "My");

        base.OnActionExecuting(filterContext);
    }
}

is it still best to do as:

public OS_Clients currentClient { 

    get {
        OS_Clients _currentClient = null;

        if (Session["CurrentClient"] != null)
            _currentClient = (OS_Clients)Session["CurrentClient"];

        return _currentClient;
    }

    set { 
        Session["CurrentClient"] = value; 
    }
}
  • 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-22T01:01:19+00:00Added an answer on May 22, 2026 at 1:01 am

    It seems that you dealing with application security in that case I would suggest to create Authorization filter, which comes much early into the action. You can put your permission checking code over there and the framework will automatically redirect the user to login page if the permission does not meet AuthorizeCore.

    Next, if the user has permission you can use the HttpContext.Items as a request level cache. And then you can create another ActionFilter and in action executing or you can use the base controller to get the user from the Httpcontext.items and assign it to controller property.

    If you are using asp.net mvc 3 then you can use the GlobalFilters to register the above mentioned filters instead of decorating each controller.

    Hope that helps.

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

Sidebar

Related Questions

I have a controller that all my controllers inherit from and I need to
When submitting one form from view, how can i also read or have controller
I have a controller action that is being executed by a link that was
I have multiple controller actions that takes an id public ActionResult Get(int? id) {
I have a HTML form, and I have a Controller Action that accepts the
I'm struggling here with a problem: I have a controller questions which has action
I have a base controller abstract class, which my other controllers inherit. This class
I have two different models that can show up in a category. In my
I have created a Base-Controller from which all the controllers inherit. Currently this controller
I have an asp.net masterpage, and All my controllers inherit from a controller base.

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.