Sharing Objects Between ASP.NET "Sites"/Projects

Discussion in 'ASP .Net' started by =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 3, 2007.

  1. I'm developing a service which is two sites: a Mobile Site and a PC-Based
    Site. The whole goal is to have them operate very similarly but, of course,
    there will be many differences:

    1. Web.configs will be different to handle cookieless vs. cookied Sessions
    2. Mobile site will have no Master Pages (unfortunately)
    3. Design of pages will be VASTLY different

    However, many elements will be exactly the same:
    a. I'll use most of the same classes for data access and other business
    objects
    b. The database in the backend is the same database

    Here's my question: What's the best strategy for building these sites to
    share code that's the same? It seems that in order to have two different
    Web.comfigs (which I think I *must* have to support the differences between
    Mobile and PC stuff), I must basically have two different sites. If I have
    two different sites, I must have two different "App_Code" directories. This
    means, I think, that I cannot share the same class files between the two
    sites and must make copies of them. This seems like a shame.

    Is there a better way to do all this?

    Thanks for your help.

    Alex
    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 3, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    bruce barker Guest

    you should create 2 sites (web projects) and 1 library project, that is
    referenced from both sites. put all shared code in the library project.
    you can create one solution for all of this.

    you could also just use one site and auto detect on session cookie. but
    above is probably better.

    -- bruce (sqlwork.com)



    Alex Maghen wrote:
    > I'm developing a service which is two sites: a Mobile Site and a PC-Based
    > Site. The whole goal is to have them operate very similarly but, of course,
    > there will be many differences:
    >
    > 1. Web.configs will be different to handle cookieless vs. cookied Sessions
    > 2. Mobile site will have no Master Pages (unfortunately)
    > 3. Design of pages will be VASTLY different
    >
    > However, many elements will be exactly the same:
    > a. I'll use most of the same classes for data access and other business
    > objects
    > b. The database in the backend is the same database
    >
    > Here's my question: What's the best strategy for building these sites to
    > share code that's the same? It seems that in order to have two different
    > Web.comfigs (which I think I *must* have to support the differences between
    > Mobile and PC stuff), I must basically have two different sites. If I have
    > two different sites, I must have two different "App_Code" directories. This
    > means, I think, that I cannot share the same class files between the two
    > sites and must make copies of them. This seems like a shame.
    >
    > Is there a better way to do all this?
    >
    > Thanks for your help.
    >
    > Alex
    bruce barker, Jun 4, 2007
    #2
    1. Advertising

  3. Bruce -

    Thanks. This is *very* helpful. You mean a "Class Library" project, right?
    That does make sense. Just one question: I *do* suppose that that mean that
    the nice, automatic compilation business that you get when you put your .cs's
    inside the App_Code directory won't happen, right? Still, it's better than
    the awful copying that I've been doing.

    Alex

    "bruce barker" wrote:

    > you should create 2 sites (web projects) and 1 library project, that is
    > referenced from both sites. put all shared code in the library project.
    > you can create one solution for all of this.
    >
    > you could also just use one site and auto detect on session cookie. but
    > above is probably better.
    >
    > -- bruce (sqlwork.com)
    >
    >
    >
    > Alex Maghen wrote:
    > > I'm developing a service which is two sites: a Mobile Site and a PC-Based
    > > Site. The whole goal is to have them operate very similarly but, of course,
    > > there will be many differences:
    > >
    > > 1. Web.configs will be different to handle cookieless vs. cookied Sessions
    > > 2. Mobile site will have no Master Pages (unfortunately)
    > > 3. Design of pages will be VASTLY different
    > >
    > > However, many elements will be exactly the same:
    > > a. I'll use most of the same classes for data access and other business
    > > objects
    > > b. The database in the backend is the same database
    > >
    > > Here's my question: What's the best strategy for building these sites to
    > > share code that's the same? It seems that in order to have two different
    > > Web.comfigs (which I think I *must* have to support the differences between
    > > Mobile and PC stuff), I must basically have two different sites. If I have
    > > two different sites, I must have two different "App_Code" directories. This
    > > means, I think, that I cannot share the same class files between the two
    > > sites and must make copies of them. This seems like a shame.
    > >
    > > Is there a better way to do all this?
    > >
    > > Thanks for your help.
    > >
    > > Alex

    >
    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 4, 2007
    #3
  4. Hi Alex,

    Based on your description, you're building two websites, one for mobile
    clients and one for normal pc clients and they have same functionality and
    backend data store, so you're wondering how to share the code logic as much
    as possible between them, correct?

    For this scenario, I think the most different of the two websites here are
    of the ASP.NET front-UI interfaces, Mobile application's front UI layout
    and display differ much from normal web application. I think what you can
    share most between them should be the middle tier business or data access
    components. Such as validation rules or data access utilities.

    As you've mentioned that you will need to create separate copy of classes
    put in each application's App_Code folder. Then, I suggest you consider
    move much classes(that is common to both applications) into a shared class
    library project. And both of the two web application can reference to the
    same class library project to use those common component classes. How do
    you think?

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jun 4, 2007
    #4
  5. Steven -

    Yes, I agree. The thing is, I really have come to love the whole idea of the
    App_Code directory because it allows me to publish the site just by copying
    all of the source files without having to compile and build and all that. I
    guess there's no way to do that when you are creating a separate class
    library, right?

    Alex


    "Steven Cheng[MSFT]" wrote:

    > Hi Alex,
    >
    > Based on your description, you're building two websites, one for mobile
    > clients and one for normal pc clients and they have same functionality and
    > backend data store, so you're wondering how to share the code logic as much
    > as possible between them, correct?
    >
    > For this scenario, I think the most different of the two websites here are
    > of the ASP.NET front-UI interfaces, Mobile application's front UI layout
    > and display differ much from normal web application. I think what you can
    > share most between them should be the middle tier business or data access
    > components. Such as validation rules or data access utilities.
    >
    > As you've mentioned that you will need to create separate copy of classes
    > put in each application's App_Code folder. Then, I suggest you consider
    > move much classes(that is common to both applications) into a shared class
    > library project. And both of the two web application can reference to the
    > same class library project to use those common component classes. How do
    > you think?
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    >
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >
    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 4, 2007
    #5
  6. Thanks for your reply Alex,

    Yes, I agree that a class library project can not offer such feature that
    make the source code directly deploy in target directory(without
    precompile). However, for optimized deployment scenario that need
    precompilation, using separate class library to seprate shared code logic
    would be good idea.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jun 5, 2007
    #6
    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. Anders K. Jacobsen [DK]

    Sharing UserControls between different sites

    Anders K. Jacobsen [DK], Dec 5, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,230
    Bryce Budd
    Dec 8, 2004
  2. Manohar Kamath

    Sharing ASP.NET code between two sites

    Manohar Kamath, Apr 6, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    455
    =?Utf-8?B?RGF2ZSBGYW5jaGVy?=
    Apr 6, 2005
  3. Replies:
    0
    Views:
    286
  4. Anders K. Jacobsen [DK]

    Sharing UserControls between different sites

    Anders K. Jacobsen [DK], Dec 5, 2004, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    124
    Bryce Budd
    Dec 8, 2004
  5. Anders K. Jacobsen [DK]

    Sharing UserControls between different sites

    Anders K. Jacobsen [DK], Dec 5, 2004, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    138
    Bryce Budd
    Dec 8, 2004
Loading...

Share This Page