Have multiple ASP.NET web projects share pages and controls

Discussion in '.NET' started by MrCeri, Jul 17, 2006.

  1. MrCeri

    MrCeri

    Joined:
    Jul 17, 2006
    Messages:
    4
    Location:
    UK
    Hi,

    I have an existing ASP.NET/C# web application which I would like to replicate for use on another project. The other project will need slight modifications to the existing site, e.g. some different site text, some different logic in code-behind, the odd extra page here and there etc., but 95% of the site will remain the same.

    My question is, what is the best practice for sharing code/pages between these two sites? I am using Visual Studio 2005, and cannot see an easy way of sharing .aspx pages, .ascx web controls, etc. between different web projects.

    Naturally I don't want to simply create a copy of every page for each site, as this leads to twice the maintenance cost of having all the shared pages in the same place.

    Many thanks in advance for any help/advice,

    MrCeri
     
    MrCeri, Jul 17, 2006
    #1
    1. Advertising

  2. MrCeri

    shark_bait

    Joined:
    Jul 17, 2006
    Messages:
    3
    i think you can link the pages....

    add existing item, then select the item and instead of clicking on Add, click on the arrow next to it and select Add as Link
     
    shark_bait, Jul 18, 2006
    #2
    1. Advertising

  3. MrCeri

    MrCeri

    Joined:
    Jul 17, 2006
    Messages:
    4
    Location:
    UK
    Nope, I'm afraid there's no "add as link" option when adding existing aspx pages to a web project in Visual Studio 2005. Shame, that would be exactly the thing I would want! :)

    Incidentally here are the possible solutions I've had suggested to me so far:

    1) Copy all of the pages to the new website, and maintain both sites independently.
    - obviously terrible from a maintenance point of view.

    2) Move all of the code behind into classes in a shared assembly, and have the aspx pages inherit from these classes. It will still be necessary to have copies of all pages on each site, but the pages would now be super-thin, almost just html. All the logic from the code behind would now be in classes that can be shared between sites.
    - still not ideal, as you still have to have a copy of each page maintained on each site, but at least there's less maintenance.

    3) Use source control to maintain a copy of each web page in each of the sites.
    - I haven't investigated this in too much detail, but I'm pretty sure it's possible. The danger here is from accidents happening where half the files in a directory are symbolically linked to other files, half are locally modified versions, and it all gets a bit confusing.

    If anyone else can think of anything else, please let me know.

    Cheers,

    MrCeri
     
    MrCeri, Jul 18, 2006
    #3
  4. MrCeri

    crushmeguy

    Joined:
    Jul 18, 2006
    Messages:
    1
    Source Control

    The simplest solution is to store your code in Visual Source Safe (or a similar source control app) and to ALWAYS check in/out your files before you modify them. This will allow you to share files from project to project, and when a change is made you simply get the latest version in all of your projects (which you should be doing by habit every time you open a project, anyway).

    I currently share twenty some controls like this, and it is absolutely simple to maintain.

    Doug
     
    crushmeguy, Jul 18, 2006
    #4
  5. MrCeri

    MrCeri

    Joined:
    Jul 17, 2006
    Messages:
    4
    Location:
    UK
    Yep, that was kind of what I was getting at with option 3 in my previous post.

    Since originally posting I have had another suggestion, which is to re-factor all of my pages as re-usable controls, and move them into a shared class library. I guess it's an extension of option 2 I mentioned previously, but taking it a big step further (and greatly reducing maintenance costs).

    This article certainly helps if anyone is interested in the details:

    http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx

    Cheers,
    MrCeri
     
    MrCeri, Jul 19, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    Share User Controls Between Multiple projects

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Aug 7, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    774
    Marre
    Aug 10, 2005
  2. Nathan Sokalski
    Replies:
    5
    Views:
    1,061
    Gaurav Vaish \(www.Edujini-Labs.com\)
    Jan 10, 2007
  3. Nathan Sokalski
    Replies:
    4
    Views:
    326
    Nathan Sokalski
    Dec 21, 2006
  4. Nathan Sokalski
    Replies:
    4
    Views:
    367
    Nathan Sokalski
    Dec 21, 2006
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,389
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page