• Subdomain.Plugin


Assembly: Subdomain.Plugin


A subdomain allows you to seperate portions of a website or API into a dedicated heirerarchy, for instance you could have specific subdomains for:

  • Searching
  • Login
  • Blogs
  • Helpdesk
  • Specific API Versions

The default subdomain for any website is typically www (world wide web) and most websites will easily function with a single subdomain, using MVC and a domain name of mywebsite.com, the default uri would be


The above uri would invoke the home controller and the same page as a uri of www.mywebsite.com/home (assuming a standard setup). Given the above examples we would have controllers for specific areas e.g.


To reconfigure to use subdomains for the above you would instead have something similar to:


This allows us to split the behaviour of a website into individual subdomains with specific areas of responsibility.

Subdomain Attribute

To enable subdomain routing for an attribute you must add a to the controller:

public class BlogController : Controller

The name of the subdomain attribute must correspond to an entry in the Configuration section in order to enable the subdomain routing.


Configuring the subdomain plugin is accomplished using appsettings.json. By default all subdomain routing is disabled, each subdomain has to be specifically enabled in order for it to work. See DNS topic for configuring CNAME or A records.

"SubdomainSettings": {
  "Subdomains": {
    "Blog": {
    "Helpdesk": {
    "Account": {

There are three distinct options to configure for enabling subdomain routing, they are:

  • DomainName - This is the name of the primary domain
  • Enabled - Setting to true enables subdomain routing, false disables this feature completely.
  • Subdomains - Configuration settings for each subdomain

Each Subdomain settings has a further 3 options:

  • Disabled - Setting to false enables subdomain routing, true disables this feature completely.
  • RedirectedRoute - This is the name of subdomain under the primary domain
  • PermanentRedirect - Determines whether the response for redirecting to a subdomain is permanent or not.

It is important to note that the name of the subdomain within the subdomains list has to correspond with the subdomain attribute applied to each controller.


It is important to note that CNAME or A records will need to be created for each type of subdomain within a root domain. This is typically accomplished by configuring the DNS entries for each domain using your domain host.


Although relatively easy to setup, additional steps need to be considered when using subdomains, they include:

  • If cookies are to be read across all subdomains, you need to ensure they have the domain set to the primary domain, i.e. ".mysebsite.com"
  • If using SSL you will need to ensure you have individual SSL certificates for each subdomain or a wildcard certificate.
  • Consideration for same-origin policy must be made.
  • Ensure security implication are met especially in respect ot cross site scripting.


The Subdomain middleware class can be used in any supported MVC website by manually configuring the application builder


If used as part of the plugin manager configuration is automatic.