简体   繁体   中英

Multiple domains, same web application on IIS 6

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 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"]

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM