8

Sometime ago I asked this question and I was told that the entry has to be made in DNS etc. I was not sure whether all this is really required or not. The kind of feature that I am looking for is shown in the screenshot below:

enter image description here

As you can see blogger lets the user choose the subdomain for his blog. How can we achieve this? I am basically developing in asp.net C#. How can I allow my users to choose subdomains like this once I have my top level domain. Currently I am developing on localhost.

halfer
  • 19,824
  • 17
  • 99
  • 186
TCM
  • 16,780
  • 43
  • 156
  • 254

2 Answers2

6

Use a wild card domain in IIS so it traps every request to the top level domain and under.

In asp.net: Create an HttpModule... this will run for every request and you can check the domain name, etc and pull in user information based on the sub-domain. An example httpmodule can be found at URL Rewriting in ASP.NET via HttpModule.

In asp.net mvc: Create a custom RouteHandler (custom based on interface IRouteHandler). Look at RouteHandler vs ControllerFactory question for an example.

Community
  • 1
  • 1
bbqchickenrobot
  • 3,592
  • 3
  • 45
  • 67
  • How do I add wildcard DNS Mapping in IIS 7.5? The article I am referring is `http://www.purpleant.com/Blogs/BrianSwanson/tabid/64/EntryId/144/Wildcard-sub-domain-for-Microsoft-IIS-and-DNS.aspx` but this is of IIS 6. How can I do it in IIS 7.5? – TCM Jul 10 '11 at 04:46
  • http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/ – bbqchickenrobot Jul 11 '11 at 01:18
  • It can also be done **without** writing an HttpModule by using [IIS UrlRewrite 2.0](http://www.iis.net/download/urlrewrite). You setup the format of your url in the web.config and then you can access that value via the querystring. – Snives Jul 20 '11 at 22:59
  • Sadly the first link seems to be dead, getting 404 error. – Steve Jones Sep 03 '17 at 13:59
  • Yes, it appears that link is dead. But fear not - MS has information on that as well: https://msdn.microsoft.com/en-us/library/bb398986.aspx – bbqchickenrobot Sep 03 '17 at 15:02
3

You need to add a wildcard DNS mapping that maps *.example.com to your webserver, and a wildcard hostname mapping telling IIS to send all subdomains to your ASP.Net website.

You can then check Request.Hostname in server-side code and use the appropriate content (or error message)

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • How do I add wildcard DNS Mapping in IIS 7.5? The article I am referring is `http://www.purpleant.com/Blogs/BrianSwanson/tabid/64/EntryId/144/Wildcard-sub-domain-for-Microsoft-IIS-and-DNS.aspx` but this is of IIS 6. How can I do it in IIS 7.5? – TCM Jul 10 '11 at 04:45