0

I'm learning .NET MVC 2 and would like to know how I could go about creating sub-domains for a list of cities that I have stored in a table. It would be nice if they were somehow created dynamically as I add cities to the table.

For Example:

  • seatle.mysite.com
  • calgary.mysite.com
  • orlando.mysite.com

I'd like for it to work in my local "Dev" environment (windows 7, IIS 7) as well as on my live site (shared hosting, unlimited sub-domains).

PercivalMcGullicuddy
  • 5,263
  • 9
  • 46
  • 65
  • 1
    possible duplicate of [Is it possible to make an ASP.NET MVC route based on a subdomain?](http://stackoverflow.com/questions/278668/is-it-possible-to-make-an-asp-net-mvc-route-based-on-a-subdomain) – 3Dave Jan 10 '11 at 20:03
  • I just went trough the post and it's about mapping subdomains to controllers and actions. I don;t really need that, just subdomains. So my case is a bit different. – PercivalMcGullicuddy Jan 10 '11 at 20:19
  • Pretty sure you need to touch your domain's DNS records to do this. Not sure how you'd do that programmatically, unless your host publishes an API (assuming that it's a hosted domain)... :/ – Dan J Jan 10 '11 at 20:30

1 Answers1

1

You'll have to create your subdomains on your DNS. Technically, you could program this into the Application_Start, but you really should figure out what list you will have and then just do the job to create them once. Alternatively, see if your DNS and webhost can do wildcard domains so that *.domainname.com will go to your website.

After you do that, Maarten Balliauw's blog has an article on how to route subdomains: http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx

ajma
  • 12,106
  • 12
  • 71
  • 90