tags:

views:

1323

answers:

5

On IIS 6, is it possible to have multiple domain names pointing to the same web application, and conditionally serve CSS from within the web application based on the domain name?

I need to host hundreds of different "skins" on the same web application, with the skin being dependent upon the domain name, and I really don't want to launch tons of web applications.

+1  A: 

1) add the desired domain names as website identifiers in the advanced property page of the Web Site Tab.

2) map the .css extension to the aspnet_isapi.dll

3) write an httpmodule that will re write the url for .css requests based on the domain name

4) enable your module via the web.config

rhinof
Is there a way to do this via API? There will be hundreds.
Pittsburgh DBA
If you only have the one site on your server. Set the site to be the default and don't set any identities. All requests regardless of domain will then go to the default web site.
Martin Brown
@Pittsburgh DBAby via API you mean via COM or using the native WIN32 API and not via the managed .NET environment ?If so you can write a native isapi filter that will perform the rewrite and register it with IIS.google on the following key words isapi filters iis
rhinof
Thank you. We considered an ISAPI filter, but we want something easier to implement.
Pittsburgh DBA
+1  A: 

If you use themes, you can change the theme, thereby changing the css, etc. in the Page.PreInit depending on the value of the domain in Request.ServerVariables["Url"] (note, there might be a better server variable to get the domain name, look it up).

If you aren't using themes, you can programatically swap out the css file by checking the same server variable.

MasterPages are going to be your friend here.

Hope that shoves you in the right direction. It is possible and common.

JasonS
I am not familiar with themes. Looking now!
Pittsburgh DBA
+1  A: 

If you are going to have different core content on the sites then I suggest putting in a global identifier to track which site a user is on and put your data in a DB somewhere for reference against that identifier. This is by far the easiest way to extend the app if each instance is unique.

You can put this into a class and have one common pattern for figuring out where stuff should map to. I suggest that once you know the mapping to cache that and then you will be able to do what you want without the latency of a thousand apps or db calls.

You will also need to add this parameter on any general DB calls so that you only get results for the domain that is being hosted. I’ve got a bit of experience with this so just leave some comments if you want to see some specific coding examples.

You can apply this technique to any file, CSS stylesheet or object for referencing purposes.

Middletone
Thank you very much. This is an insightful comment. I am still trying to pick an "accepted" answer. Voted you up.
Pittsburgh DBA
+3  A: 

+1 to rhinof for adding multiple identities, but creating a HttpModule is a bit over kill. You can simply switch the URL of the tag in a Master Page by examining the contents of Request.Headers["HOST"]

Martin Brown
This looks very promising.
Pittsburgh DBA
Thank you. I am sorry it took me so long to close this.
Pittsburgh DBA
+1  A: 

Yes, this should be simple to do. I'd go with the approach of mapping the domain names to your app using host headers in IIS. Then, as Martin said, interrogate Request.Headers["HOST"] in your app to switch the stylesheet.

remotefacade