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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:31:57+00:00 2026-05-25T06:31:57+00:00

I am using ASP.NET MVC to develop an application framework. Essentially, the end goal

  • 0

I am using ASP.NET MVC to develop an application framework. Essentially, the end goal is to be able to log into an admin interface, create a new tenant with custom settings, enable the modules they want (blog, shopping basket, etc)… job done – satisfied customer with new website. I’m not using separate applications because there will be a lot of shared code and it would be easier to maintain this way, and also because it would be pretty easy to bring a new, identical node online at peak times.

Depending on what modules are loaded for the tenant, different routes are applicable for each tenant. As I see it, there are three options:

  • Have all tenants share the same route collection – however if there are a lot of modules it’ll be searching through a lot of routes it doesn’t need to, and some modules may well have conflicting routes.

  • Add the necessary routes for each tenant to the global route collection and extend the route class to look at the domain as well – but this could quickly end up with hundreds of routes as more tenants are added.

  • Work out what tenant is being accessed first and then only search their own private route collection – this would be ideal, but I’ve searched for hours and have absolutely no idea how to do it!

So can anyone point me in the correct direction for the third option or explain why either of the first two aren’t really that bad?

  • 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-25T06:31:57+00:00Added an answer on May 25, 2026 at 6:31 am

    How will each website be distinguished in your app? If we assume each tenant will be identified by a unique domain name or subdomain name, then you can accomplish your routing with one route and some RouteConstraints. Create two constraints, one for controllers, the other for actions. Assuming that you will have tables in your database which list the available controllers/actions for a specific tenant, your constraints would be as follows:

    using System; 
    using System.Web; 
    using System.Web.Routing;  
    
    namespace ExampleApp.Extensions 
    { 
        public class IsControllerValidForTenant : IRouteConstraint
        {
            public IsControllerValidForTenant() { }
    
            private DbEntities _db = new DbEntities();
    
            public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
            {
                // determine domain
                var domainName = httpContext.Request.Url.DnsSafeHost;
                var siteId = _db.Sites.FirstorDefault(s => s.DomainName == domainName).SiteId;
                // passed constraint if this controller is valid for this tenant
                return (_db.SiteControllers.Where(sc => sc.Controller == values[parameterName].ToString() && sc.SiteId == siteId).Count() > 0);
            }
        }
    
        public class IsActionValidForTenant : IRouteConstraint
        {
            public IsActionValidForTenant() { }
    
            private DbEntities _db = new DbEntities();
    
            public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
            {
                // determine domain
                var domainName = httpContext.Request.Url.DnsSafeHost;
                var siteId = _db.Sites.FirstorDefault(s => s.DomainName == domainName).SiteId;
                // passed constraint if this action is valid for this tenant
                return (_db.SiteActions.Where(sa => sa.Action == values[parameterName].ToString() && sa.SiteId == siteId).Count() > 0);
            }
        }
    }
    

    Then, in Global.asax.cs, define your route as follows:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
            new { controller = new IsControllerValidForTenant(), action = new IsActionValidForTenant(),}
        );
    }
    

    When a request comes in, the constraints will examine whether the controller and action are valid for the domain, so that only valid controllers and actions for that tenant will pass the RouteConstraints.

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

Sidebar

Related Questions

I am using asp.net MVC to develop an application that will have ajax interactions.
Hey guys! I'm using ASP.NET MVC to develop an application for a library with
I'm using ASP.NET MVC to develop a web application, deploying to IIS 7. I've
Hai guys, As i want to develop an application using asp.net MVC, i dont
I am using ASP.NET MVC application. However I am not able to understand the
I am using ASP.NET MVC to develop a web application and would like to
I am using asp.net mvc for an application. I've taken some guidance from Rob
The project is developed using ASP.NET MVC framework and heavily relies on .NET 3.5.
I'm using MonoDevelop on Mac OS X Snow Leopard to develop an ASP.NET MVC
I have been learning to develop websites using ASP.NET MVC 2 for work... 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.