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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:12:03+00:00 2026-05-13T23:12:03+00:00

I would like to setup a multi-tenant ASP.NET MVC app. Ideally, this app would

  • 0

I would like to setup a multi-tenant ASP.NET MVC app. Ideally, this app would have a route with {tenant}/{controller}/{action}/{id}, each tenant representing an logical instance of the app (simply independent multi-user accounts)

The fine grained details how do that are still quite unclear to me. Any guide available to setup such multi-tenant scheme with ASP.NET MVC?

  • 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-13T23:12:03+00:00Added an answer on May 13, 2026 at 11:12 pm

    I am currently working on a similar project using ASP.Net MVC, Forms Authentication and the SQL providers for Membership/Roles/Profile. Here is the approach I am taking:

    1. Register the default route as `{tenant}/{controller}/{action}/{id}

    2. Change the default behavior of the FormsAuthenticationService that comes with the standard MVC template. It should set the UserData of the authentication ticket to include the tenant name (from your route).

      public void SignIn(string userName, bool createPersistentCookie, string tenantName)
      {
          var ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(30),
                                                     createPersistentCookie, tenantName);
          var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
          HttpContext.Current.Response.AppendCookie(cookie);
      }
      
    3. In your global.asax file to do some tenant security checking and allow partioning of users between tenants in one membership database

      protected void Application_AuthenticateRequest(object sender, EventArgs e)
      {
          //Since this method is called on every request
          //we want to fail as early as possible
          if (!Request.IsAuthenticated) return;
          var route = RouteTable.Routes.GetRouteData(new HttpContextWrapper(Context));
          if (route == null || route.Route.GetType().Name == "IgnoreRouteInternal") return;
          if (!(Context.User.Identity is FormsIdentity)) return;
          //Get the current tenant specified in URL 
          var currentTenant = route.GetRequiredString("tenant");
          //Get the tenant that that the user is logged into
          //from the Forms Authentication Ticket
          var id = (FormsIdentity)Context.User.Identity;
          var userTenant = id.Ticket.UserData;
          if (userTenant.Trim().ToLower() != currentTenant.Trim().ToLower())
          {
              //The user is attempting to access a different tenant
              //than the one they logged into so sign them out
              //an and redirect to the home page of the new tenant
              //where they can sign back in (if they are authorized!)
              FormsAuthentication.SignOut();
              Response.Redirect("/" + currentTenant);
              return;
          }
          //Set the application of the Sql Providers 
          //to the current tenant to support partitioning
          //of users between tenants.
          Membership.ApplicationName = currentTenant;
          Roles.ApplicationName = currentTenant;
          ProfileManager.ApplicationName = currentTenant;
      }
      
    4. Partition each tenants data. Here are two options:

      4a. Use a separate database for each tenant. This provides the best data security for your tenants. In the shared membership database, add a table that is keyed on unique appid for each tenant and use this table to store and retrieve the connection string based on the current tenant.

      4b. Store all data in one database and key each table on the unique tenant id. This provides slightly less data security for your tenants but uses only one SQL Server license.

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

Sidebar

Related Questions

I would like to setup a admin page (ASP.NET/C#) that can add IIS host
Is there a Bayesian filter library for .NET? I would like to setup a
I would like to know how to setup an SVN repository with LDAP authentication.
I would like to have a reference for the pros and cons of using
I would like to set up some WMV Video Streaming, using Windows 2003's Streaming
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it
I would like to test a string containing a path to a file for
I would like to sort an array in ascending order using C/C++ . The
I would like to use a language that I am familiar with - Java,

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.