views:

45

answers:

2

I have built a website and now the customer wants to split it between three different domains. What is the best way to do this? This is what I have so far.

  • c:/website1/ points to www.website1.com
  • c:/website1/vd1/ points to www.website2.com
  • c:/website1/vd2/ points to www.website3.com

The webhost I'm working with has done it the following way, but now I'm getting a bunch of errors that seems like it's not seeing the App_code folder. Do I need to make a lot of changes? How does this affect the location references?

+2  A: 

The problem you have is that by configuring your sites as you have done, www.website2.com and www.website3.com are separate applications, and cannot see any of the content or code that exists outside of /vd1/ or /vd2/ respectively (so yes, that would be the /app_code/ folder in c:\website1\, along with any images, css, user controls, master pages, etc that might be in there).

If all you are sharing is some logic in the /app_code/ folder, are you able to copy that to a new project in Visual Studio? Ideally you'd want to create a new Class Library project, and just have the .cs files in there. Compile that into it's .dll file, and in your web site project, Add a Reference to that library.

However this doesn't work as well for user controls, or other common pages you might want to be using (such as login, registration, etc).

Then ensure that you create a /bin/ folder in each of the virtual directories and copy the library into there as well. You may need to ask your webhost to configure them as Applications in the www.website1.com as well.

Edit to respond to comment

Then yes, you probably do have quite a bit of work ahead of you, but without knowing the reason why you're splitting out parts of the site like this onto different domains, I can't really offer a solution as to how to do that - as Bryan points out below, you can map multiple domains (known as host-headers) to a single site in IIS, so you could have all three pointing to the same root.

If you're then looking to have a different look and feel, you'd want to look at having a core "Base Page" type class, that inherits from System.Web.UI.Page and have your pages inherit from that instead, you can then swap out the templates based on the ServerName in the URL - if you're using MasterPages for example you would need to do this in the OnPreInit method.

You would also be able to add additional logic in there to ensure that the user is sent to the correct section of the site if that's a requirement.

Zhaph - Ben Duguid
I need to share more than just the app_code folder. I have a lot of admin pages (in fact the whole CMS) that I would need to copy the pages to each of the virtual sites. I'm thinking that I should maybe just redirect the user to the correct "home" page based on the domain they come from. It just seems like there would be a better/standard way of doing this.
Scott J.
A: 

Just because you have multiple domains doesn't mean you need separate applications. What is the point of these virtual directories? IIS will happily serve multiple domains to the same app.

Bryan