1

i have created a new web forms application in visual studio 2010 with just two pages Default.aspxand About.aspx. what i want is that when i debug the app in visual studio development server it and enter http://company1.localhost:1023 it should just display Default page with message This is default page for company1. How can i do it with just playing with url routing as opposed to doing settings in IIS
Note: I understand that multi-tenancy is a big word and should not be used for such a simple scenario but my requirements are simple. i would just run same instance of the application for each company with no extension points. This question could also be stated as how can i create subdomains programmatically.

Muhammad Adeel Zahid
  • 17,474
  • 14
  • 90
  • 155

1 Answers1

3

You have to configure IIS (and perhaps DNS) correctly for this work. For example, all your sub-domains should handle by the designated web-site in IIS. Typically, you may configure IIS to handle all host-headers if there are only single web site but in case of multiple web-sites, IIS is typically configured to differ by host header. So getting this configuration right is the important part for you.

Once you reach to the correct web-site, resource handling will be done by IIS meta-base. So in this case, it would re-direct to configured default resource for the site. If resource-name is present then extension (htm, aspx) will decide the handling. Aspx extensions will handled by ASP.NET and then all you need to do is to look up current host header and take a decision accordingly. For example,

protected void Page_Load(object sender, EventArgs e)
{
    if (request.Url.HostNameType == UriHostNameType.Dns)
    {
       var hostParts = Request.Url.Host.Split('.');
       // you may validate if sub-domain name is present or not
       lblMessage.Text = "This is default page for " + hostParts[0];
    }  
}
VinayC
  • 47,395
  • 5
  • 59
  • 72
  • I don't think this helps him. He explictly asks for the solution not to use IIS. No saying my answer is any better of course – Crab Bucket Mar 06 '12 at 09:36
  • 1
    @CrabBucket, I guess you missed the point. What OP needs has to be configured at web server level - ASP.NET code including routing (or any app/ISAPI level code) will come into play only when the request can successfully reach ASP.NET run-time (which needs IIS configuration). – VinayC Mar 06 '12 at 11:19
  • I have missed the point. It's different defaults for different hosts. I thought there must be something else. Thanks for that - i'm deleting my answer – Crab Bucket Mar 06 '12 at 11:39
  • I missed that too Crab. Thanks vinay for the help – Muhammad Adeel Zahid May 08 '12 at 06:06