views:

33

answers:

3

I have a few applications that need to share a common set of markup.

Scenario: I might have www.site1.com, www.site2.com, and www.site3.com. On all sites, /care/contact-us.aspx and /care/faqs.aspx will be exactly the same, but every other page will be totally different.

Issue: I'm attempting to not duplicate the .aspx files for each of these sites and would like to have a /care virtual directory that would include contact-us.aspx and faqs.aspx that each of these sites would use. I have seen this post from Scott Gu, but I'm looking for any other solutions/ideas.

Question 1: What would be the best way to set this up to share the /care directory? Question 2: Any ideas about also sharing the code behind.

Background, if you care: In a legacy application (asp classic/vbscript), we have the ability to use a /common virtual directory for sites to share common markup and code (since they're all mixed together in .asp files).

Thanks in advance to any help or ideas!

A: 

Simply setup a virtual directory in IIS for each of the apps that points to the same physical directory.

Here's a good reference:

http://support.microsoft.com/kb/324785

Nissan Fan
This works for static files but I don't think that this is what Chuck is after. As far as I know (that is, I could be wrong) you cannot just place ASPX files in a virtual directory and let different web sites "share" them. They'll step all over each others' toes: precompiled sites, for example, will all assign different names to the compiled versions of the ASPX files. Publishing with Fixed names and single page assemblies *might* take care of this - but then I think you'd run into other problems as the published DLLs struggle for control of the files.
Mark Brittingham
I don't disagree. The kb article covers off this. I don't find any solution other than just having 3 copies to be optimal myself.
Nissan Fan
A: 

I use a virtual directory in order to share HTML and Image files between sites. To share ASPX files, things are a bit different - and harder.

When we share HTML files, we do not just link to that file because it would screw up the menu (different sites have different menus - we just want the content of the HTML files). So I created a page (e.g. "ShowContent.aspx") that opens up the HTML file, reads the contents as a string and assigns the string to an ASP label control. This may work for you as-is if you don't generate the content dynamically in your shared ASPX files.

Even if you do, hope is not lost. First, create a project that incorporates JUST the common ASPX files, build it and place the project files in a known location (http://shared.yoururl.com). Now, instead of pulling the contents by accessing a file, simply read the contents off using a WebRequest object:

        WebRequest wrContent = WebRequest.Create("http://shared.yoururl.com/CommonInformation.aspx");
        Stream objStream = wrContent.GetResponse().GetResponseStream();
        StreamReader objStreamReader = new StreamReader(objStream);
        string pageContent = objStreamReader.ReadToEnd();

Then display the pageContent on your blank page.

If your common pages are data entry forms then I'm afraid your only hope is to place them in a common source directory that multiple projects share. You'd share the source but would publish the files with each project. This is likely to be messy though: you may make changes in one that break other projects because they now have the possibility of interdependency.

Mark Brittingham
A: 

This is actually pretty hard, and i'd recommend you either bite the bullet and go with the scott gu answer or use the solution we chose, which was to use the svn:externals property within subversion to import a directory from a "shared" repository. Subversion manual reference. If you use a different version control system i would guess it would have something similar but you're on your own in that case.

12 Dogs