Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I put classes when using Web Application project type of Visual Studio .NET instead of Website? (ASP.NET)

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?

like image 929
Jader Dias Avatar asked May 21 '09 17:05

Jader Dias


People also ask

What is the difference between web project and website in Visual Studio?

The simple answers are as follows: New Web Site - creates code behind pages that are compiled at the server when page is requested. New Web Project - creates pre-compiled pages into one or more assemblies (entire site even), and deployed on server.

What is Visual Studio .NET how it fills in the .NET framework?

Visual Studio . NET is an application development tool for writing an application; the . NET Framework provides the infrastructure required to run those applications.

How to create a web service project in Visual Studio Code?

Click on File >> New >> Project as given below. Once you click on Project, you will see the following pop-up window. Here, choose ASP.NET Web Application (.NET Framework) and give it a name as I have given - WebServiceProject. Click on OK. Select the Empty template. It creates a solution having the following solution structure.

Is it possible to create a website in Visual Studio?

(ASP.NET) - Stack Overflow 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 Stack Overflow About Products For Teams Stack OverflowPublic questions & answers

How do I create a core web application in Visual Studio?

In the New Project dialog box in the left pane, expand Visual C#, expand Web, and then choose .NET Core. In the middle pane, choose ASP.NET Core Web Application. Then, name the file MyCoreApp and choose OK. If you don't see the ASP.NET Core Web Application project template, you can get it by adding the ASP.NET and web development workload.

How do I create a web application in ASP NET?

On the Create a new project window, enter or type ASP.NET in the search box. Next, choose C# from the Language list, and then choose Windows from the Platform list. After you apply the language and platform filters, choose the ASP.NET Core Web Application template, and then choose Next.


6 Answers

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.

like image 152
NotMe Avatar answered Oct 12 '22 19:10

NotMe


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.

like image 26
Vikram Avatar answered Oct 12 '22 19:10

Vikram


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.

like image 37
Andrew Hare Avatar answered Oct 12 '22 19:10

Andrew Hare


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

like image 44
George Avatar answered Oct 12 '22 20:10

George


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.

like image 42
Jason Kester Avatar answered Oct 12 '22 18:10

Jason Kester


I use /Shared/Classes for general purpose classes used throughout the site. I like putting the rest of the classes in a Classes folder where they are used such as /blog/Classes/.

-- EDIT--

The answer above was how I stored classes in Web Forms application projects. Now that I am using MVC, I store general purpose classes in /Classes and non-general classes in subfolders under /Classes such as /Classes/Blog. In short, Old_App_Code has been renamed to Classes. This seems like a natural extension to the naming conventions I see Microsoft using in MVC, plus it works with my old Web Forms pages too.

like image 27
Theophilus Avatar answered Oct 12 '22 18:10

Theophilus