Matt Hamsmith
Matt Hamsmith

Reputation: 4036

Can subdomains be managed programmatically in an ASP.Net application?

I have an application to be written in ASP.Net 3.5 that needs to manage subdomains for a different website. The managing website and the controlled website are hosted on different Windows servers, but both run IIS 6.0.

The management website needs to provide a UI that can add or delete subdomains on the controlled site such that requests to those subdomains (i.e., mysubdomain.controlledsite.com and thatothersubdomain.controlledsite.com) navigate to different sections of the controlled sites web application (or, if necessary to set all of this up, to different web applications, which then also have to be created or deleted programmatically).

Where do I get started with this? Is this even possible? I've seen on some other SO questions (Is it possible to make an ASP.Net MVC route based on a subdomain?) something about routes, but I don't know if that fits my situation or not (I'm not using MVC). I can modify the code on both the management website and the controlled website, so if there is programming to be done to make this work on either end, I can do that.

To be specific, if the code stays the way it is on the controlled site (I can change if necessary), I need to receive requests like http://xxxx.mysite.com/ and map that to http://www.mysite.com/Home/xxxx/ while keeping the URL that the client sees as the former.

Upvotes: 3

Views: 1296

Answers (2)

Stephen M. Redd
Stephen M. Redd

Reputation: 5428

The default routing framework included with asp.net MVC cannot use the domain portion of URLs. I was a tad disappointed by that myself. But there is an article about using a custom RouteBase to enable the subdomain scenario. I haven't tried it yet though so I can't vouch for the technique described, but it looks promising as a starting point at least.

As for the admin web tools to manage all that... you will need to roll your own admin tools. How you do that depends a lot on how your applications are designed. I'd just tie both apps to the same SQL database to store each subdomain route. The admin interface for that should be rather trivial. Just a rather simple set of pages to do the CRUD operations on the routes stored in the DB is all you'd need.

In the global.asax of the other site (the public one) you'd just fetch the routes from the DB and register each one individually.

Upvotes: 0

RobV
RobV

Reputation: 28646

You could possibly achieve this by using URL rewriting which you can do in ASP.Net by writing a HTTP Module (a class that implements IHttpModule) and using the RewritePath method of the HttpContext object

You could design your module so it rewrites URLs based on some configuration file which your management application can alter as appropriate.

The following links explain the concepts more:

With IIS 6 configuration of these can be slightly trickier, search for articles on configuring wildcard paths.
Plus I'm not entirely sure if this approach will work with subdomains or not.

Upvotes: 2

Related Questions