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?
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:
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With