Search code examples
c#asp.net-mvcasp.net-mvc-4white-labelling

How to serve multiple URL's from the same MVC C# code


I have an MVC4 webapplication serving a website. Now I want to use that same webapplication for serving other websites (other URL's) as some sort of whitelabel engine. Essentially I want to use same controllers but customize on header, style and occasionally on content.

I don't want to create variants of the same webapplication. What's the best way to go about this? I was thinking about detecting the URL from each controller and acting upon that. But it feels like detecting the URL could be done higher in the call stack.

Of course, other solutions are welcome as well. I'm basically looking for the most pragmatic way to implement this.


Solution

  • If they will be on different domain names, just check the host header. Then in your table where you have all the whitelabel information (for instance, tbl_Site), just add a new column: Host.

    Then in your controller, read the host header and use that to query your tb_Site and determine what site they are accessing and customize on that.

    You will need to have all of the domain names point to the same (static) IP address.