In this Article, you will learn about the project structure and significance of each file created by ASP.NET Core application using Visual Studio 2019. The following is a default project structure when you create an empty ASP.NET Core application in Visual Studio.
The structure of a typical .NET Core project consists of various files and folders. Here is an overview of the common project structure.
1. Properties Folder
The properties folder may contain project-specific configuration files, such as launchSettings.json, which defines how the application should be launched and debugged.
2. Dependencies
This section contains all the dependencies required by your project. It includes NuGet packages, project references, and other external dependencies.
3. wwwroot Folder
The wwwroot folder is a default folder in an ASP.NET Core application that is used to store static files that will be served directly to clients, such as HTML, CSS, JavaScript, images, and other static assets.
Here are some key points about the wwwroot folder in ASP.NET Core.
4. Configuration Files
Configuration files like appsettings.json or appsettings.Development.json store application settings and configurations. These files can be used to define connection strings, logging settings, and other application-specific configurations.
You can now start developing your web application by adding controllers, views, and other necessary components using the powerful features provided by Visual Studio.
5. Program.cs file
It serves as the entry point for your .NET Core application and is essential for starting the application and handling requests. The Program.cs file is responsible for setting up the application host, configuring the web server, and specifying the startup class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Testapp
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
});
}
}
The above code defines the following points.
6. Startup.cs file
The Startup.cs file is a crucial part of the .NET Core application's configuration. It allows you to set up services, configure middleware components, and define the behavior of the application based on the current environment.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Testapp
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
}
}
The above code defines the following points.