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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:25:45+00:00 2026-05-20T15:25:45+00:00

I have an asp.net mvc app which has membership implemented. So a user has

  • 0

I have an asp.net mvc app which has membership implemented.
So a user has to log in. Each user belongs to a organisation (multi-tenancy).

How would I handle the organisation parameter globaly? I was thinking this could be a good thing for a global filter because all the data needs to be filtered for the given organisation. And the organisation is connected with the username but not in the same table.

for example I have a index action like this

public ActionResult Index()
{
var result = _repository.GetListByOrganisation(organisation);
return View(result);
}

I was thinking about having a global attribute thats queries the db for an organisation based on a giving username. Since my controller already contains the authorize attribute I have the user name. It would be nice to cache the organisation (session, controllercontext) and not query the organisation from db on each request.

Is this a way to implement something like this? Or are there other ways which would be better? And how can I set a property on the controller / controllercontext from whithin a filter?

So any thoughts on this as well as comments would be great…

  • 1 1 Answer
  • 1 View
  • 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-20T15:25:46+00:00Added an answer on May 20, 2026 at 3:25 pm

    I would do this via DI.

    You can use either a third-party DI container or your own code. Either way, you want to set the organization ID on a per-request basis.

    So you’ll be creating a unit of work and injecting that in your controller. For the sake of simplicity, let’s pretend that your unit of work is the _repository field in your sample code, even though most real-world apps are more complex.

    You add a constructor parameter to the controller:

    public FooController(IFooRepository repository)
    {
        this._repository = repository;
    }
    

    …and an organization ID on FooRepository:

    public class FooRepository: IFooRepository
    {
        public FooRepository(long organizationId)
        {
            this._organizationId = organizationId;
        }
    }
    

    Now in either your DI container setup or a MVC controller factory, you set this all up:

    builder.Register(c => new FooRepository(GetOrgIdForCurrentUser()).As<IFooRepository>();
    builder.Register(c => new FooController(c.Resolve<IFooRepository>());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC app which has a bootstrapper class that configures log4net
I have an ASP.NET MVC web app which has a really basic subscription system
I have an ASP.NET MVC server app and client code which uses jquery. I'd
In my ASP.NET MVC app, I have a fairly complex edit page which combines
In my ASP.NET MVC app, I have an interface which acts as the template
I have an object which contains models for my ASP.NET MVC web app. The
I have an ASP.NET MVC app and I want to add to each page
I have an ASP.NET MVC App, which use EF code First, for some reason
I'm working on an ASP.NET MVC App that has buttons that have the server
We have an ASP.NET MVC web app which allows users to publish messages onto

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.