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?
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.
Visual Studio . NET is an application development tool for writing an application; the . NET Framework provides the infrastructure required to run those applications.
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.
(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
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.
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.
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.
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.
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.
I normally have three projects within a solution. The web app, the web library (base pages etc) and the DAL. This keeps everything clean.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With