Welcome to the essential guide for starting your journey with ASP.NET Core! This tutorial series will walk you through the fundamental concepts and steps to build your first web application using this powerful, cross-platform framework.
Before you begin, ensure you have the following installed:
We'll start by creating a basic web application. You can do this using the .NET CLI or your IDE.
Open your terminal or command prompt and run the following commands:
dotnet new webapp -o MyFirstAspNetCoreApp
cd MyFirstAspNetCoreApp
This creates a new directory named MyFirstAspNetCoreApp
containing your project files.
MyFirstAspNetCoreApp
) and click "Next".Your new project will have a directory structure like this:
MyFirstAspNetCoreApp/
├── MyFirstAspNetCoreApp.csproj
├── Pages/
│ ├── Index.cshtml
│ ├── Privacy.cshtml
│ └── _Layout.cshtml
│ └── _ValidationScriptsPartial.cshtml
│ └── Error.cshtml
│ └── _ViewStart.cshtml
│ └── _ViewImports.cshtml
├── Properties/
│ └── launchSettings.json
├── appsettings.Development.json
├── appsettings.json
├── Program.cs
└── README.md
Key files include:
Program.cs
: The entry point of your application.Pages/Index.cshtml
: The main page of your web app..csproj
: The project file that defines your project's dependencies and configuration.Let's see your application in action!
Navigate to your project directory in the terminal and run:
dotnet run
Open your web browser and go to https://localhost:5001
or http://localhost:5000
. You should see the default ASP.NET Core welcome page.
Click the "Run" button (often a green play icon) or press F5
.
Tip: You can change the default port in the Properties/launchSettings.json
file.
ASP.NET Core often uses Razor Pages for building web UIs. Each .cshtml
file represents a page, and it can optionally have a corresponding .cshtml.cs
file for the page's logic (the "code-behind").
For example, Pages/Index.cshtml
might have a corresponding Pages/Index.cshtml.cs
file which inherits from PageModel
. This model can handle data binding, page logic, and interact with services.
Congratulations! You've successfully created and run your first ASP.NET Core application. Continue exploring these topics: