Sharing Objects Between ASP.NET "Sites"/Projects

G

Guest

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
 
B

bruce barker

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)
 
G

Guest

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
 
S

Steven Cheng[MSFT]

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.
 
G

Guest

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
 
S

Steven Cheng[MSFT]

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top