views:

91

answers:

3

I don't know if question in the title was clear enough.

Let's say that you have 2 or N domains pointing on the same ip address, your server (in my case Windows Server with IIS) and you want to make custom site for every domain name so you have to detect which domain is user currently using.

There should be two "custom sites". One is Administration aplication site with just one domain name pointing on it, and the other is aplication that handles multiple domain names and based on it displayes different sites.

Good example is shoutem network. At http://www.shoutem.com/ is administration page and aplication instances are http://zrikka.com/ and http://punkt.com.hr, separate aplication that handles different domain names.

Is it possible?

+3  A: 

What you want to accomplish isn't handled inside of ASP.Net, but at the IIS level. You specify what domains each "site" in IIS should handle. Typically, you'll have one that handles all domains that resolve to the IP, but you can have several sites bound to the IP should all have completely different docroots (ie, different applications/site files). The point is that you shouldn't have to worry about this in your application code.

Here's the MSDN docs on how to do it in IIS6.

Tim Coker
+2  A: 

At the HTTP protocol level, this is accomplished using the Host: header. For example, a simple GET request for a root page might look like:

GET / HTTP/1.1
Host: example.com

In this case, the Host: header tells the server that the browser went to the site example.com and is looking for the root page (/) from that site. Another request might be:

GET / HTTP/1.1
Host: example.org

If the same server handles both example.com and example.org, then the HTTP server can distinguish between requests in this way.

In your case, IIS is the component receiving these headers and directing the request to the appropriate site.

Greg Hewgill
A: 

If you want your single application to handle different domains on the same IP, you should check your request context, for example:

string host = HttpContext.Current.Request.Url.Host;
switch (host.ToLower())
{
    case "domain1.com":
    // do something
    break;
    case "domain2.com":
    // do something
    break;
    default: //unknown domain
    // do something
    break;
}

Knowing which host addresses you may handle, check it.

If you'd like to point different domains to different web sites on the same IP and IIS, you should configure IIS, in this case check Tim's answer.

Viktor Jevdokimov