views:

369

answers:

6

I have plenty experience creating ASP.NET Websites in the Visual Studio. But there is an alternative way to do the same thing that is through Web Applications, which have slightly different file structure.

Since I created my first Web Application I couldn't use classes (.cs files) in the App_Code folder anymore, they were not seen by the ASPX and ASHX classes unless were moved to the same file.

It happens that I use the same classes across many files and I don't want to have multiple copies of them. Where do I put those classes? There is any solution without creating another project?

+1  A: 

Why do you not want to create another project? This would be the simplest approach as all your classes would be housed in that assembly which you could project-reference in your web application and then have access to everything across the entire project.

I would highly recommend that you consider this approach.

Andrew Hare
there are lot of times when you really need to have 1 or 2 classes which are too specific and it makes sense to have them in the web application project. for eg. we have a BasePage class [inherited from web.ui.page] which contains the web application specific code to be executed on each page load and instead of using HTTPContext, etc in a class library, we simply put this class in our web app.
Vikram
I would recommend this as well. If you have a common library that you use across several projects - make your solution consist of three projects: The WebApp, the application specific classes and the generic library. In the way a Web Application project is supposed to work (compiling before publishing) this does help.
Tomas Lycken
+1  A: 

We have been using Web Application project type in VS 2008 for all our projects and put our common classes in AppCode folder instead of App_Code folder. It works absolutely fine, we access our classes across all the pages in the application without any problem at all.

Vikram
+3  A: 

With Web Application Projects you have a lot more freedom. Just create subfolders under your project to hold your classes. For example, you could have a folder named "DAL" to hold the Data Access Layer items.

Optionally, you can create an assembly project and put your classes in there and just reference it from your WAP.

Ultimately the structure is going to boil down to how many classes you will have.

Chris Lively
A: 

Hi,

I highly recommend that you put all your classes (domain objects) in a separate project. This way you will be easily able to write test against your business layer (domain objects) and your classes will be portable. Portable means that you can send your DLL to another developer and he/she can easily reuse the classes you developed.

azamsharp
+1  A: 

I normally have three projects within a solution. The web app, the web library (base pages etc) and the DAL. This keeps everything clean.

George
A: 

Put them anywhere you want. I tend to keep the little project-specific helper classes and base pages in a /Helpers folder under the web project, but split out DataLayer stuff and general-purpose reusable helpers to their own separate projects.

Jason Kester