Getting Started with ASP.NET Core

This guide will walk you through the initial steps of creating and running your first ASP.NET Core application. ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, internet-connected applications.

Prerequisites

Before you begin, ensure you have the following installed:

Creating Your First ASP.NET Core Application

You can create an ASP.NET Core application using the .NET CLI. Open your terminal or command prompt and navigate to the directory where you want to create your project.

Using the .NET CLI

  1. Create a new project using the web API template:
    dotnet new webapi -o MyWebApiApp
    

    This command creates a new directory named MyWebApiApp and generates the project files inside it.

  2. Navigate into the project directory:
    cd MyWebApiApp
    
  3. Run the application:
    dotnet run
    

    The CLI will output the URL(s) where your application is listening, typically something like https://localhost:5001 and http://localhost:5000.

Note: If you are using HTTPS and encounter certificate trust issues, you may need to trust the .NET development certificate. The dotnet run command usually prompts you if this is necessary. You can also run dotnet dev-certs https --trust to manually trust it.

Running with Visual Studio

  1. Open Visual Studio.
  2. Select Create a new project.
  3. Search for "ASP.NET Core Web API" and select the template.
  4. Click Next.
  5. Enter a project name (e.g., MyWebApiApp) and a location.
  6. Click Next.
  7. Select the .NET version and configure additional settings as needed.
  8. Click Create.
  9. Once the project is created, press F5 or click the Run button to start the application.

Exploring the Project Structure

After creating the project, you'll find a basic structure that includes:

Making Your First API Call

With the application running, you can make an API call. If you used the default template, try accessing the weather forecast endpoint:

Open your web browser or use a tool like curl or Postman and navigate to: https://localhost:[PORT]/weatherforecast (replace [PORT] with the port number shown when you ran dotnet run, e.g., 5001).

You should see a JSON response containing an array of weather forecast objects.

Tip: For more complex applications, you'll want to learn about routing, model binding, dependency injection, and more. Continue exploring the documentation!