views:

135

answers:

3

Hello,

I am currently working on a project which involves three different websites with a lot of common functionality. At the moment the common functionality is placed in a different website full of user controls.

The problem is sharing the user controls across the multiple websites. Looking around on SO and other websites, the only solution seems the be using virtual directories. As this is a workable solution (we us this at the moment) it doesn't seem as a "clean" solution.

Which "best practices" exist on sharing common functionality (including the GUI/HTML) between different site?

Is it (for example) possible to create a single Web Application project and deploy subdirectories (each with their own web.config) to different production environments?

+1  A: 

There is a solution for sharing user controls by building user control libraries described by ScottGu. In my opinion this solution isn’t very clean too, because you have to copy precompiled files around to make this solution work.

I decided to use custom web controls in separate class libraries to share common UI functionality. But maybe Scott’s solution works for you.

Dirk
A: 

IMHO it is better to use Virtual Directory solution even though it is not clean. This would solve a lot of headache since you can make use of it for multiple websites without the need to deploy extra files in each website and if there is a change you have to do it in one place only.

HTH

Raja
+1  A: 

I've been dealing with this for quite some time now, and have used both Virtual Directories and "user control library" approaches, and have found them both wanting. I'm surprised that microsoft hasn't addressed this issue to compile the user controls to be used like server controls.

Anyways...

There's two conveniences that most of us look for when attempting a user control library:

  1. Easy to develop against. If we change a user control, we want to do it one place. We want to be able to both edit and debug within the web we're working, without having to manage multiple copies of an ascx file.
  2. Easy to deploy. We want to be able to grab and publish the ascx files in multiple web sites without much hassle.

Unfortunately, Virtual Directory approach only addresses #2, and "user control libraries" addresses #2, and only part of #1. With a "user control library", you can debug against the user control library source, but if you edit the ascx in your working web, the changes will be over written next time the "user control library" is built. This is similar to how a server control operates: has to be edited elsewhere and has to be compiled to be updated. The exception being that "user control libraries" must be copied, instead of just updating a .dll reference.

Solution?

What I've used to solve #1 are symlinks. Create a common controls folder in your repository, and symlink that folder in to each of the webs as you desire. Any changes you do to the symlink folder are done to the source common controls folder.

To solve #2, I just deploy the full websites with the controls copied to their appropriate locations. You could also easily do a Virtual Directory instead, and not roll out the symlinked folder in each website. I tend to lean away from Virtual Directories for the common user controls hosting source in fear of performance issues (lots of webs, tons of traffic).

I hope this helps!

Albert Bori