MSDN Community ASP.NET Core Introduction

Getting Started with ASP.NET Core

ASP.NET Core is a cross‑platform, high‑performance framework for building modern, cloud‑based, Internet‑connected applications. Whether you’re building web APIs, MVC web apps, or real‑time services, ASP.NET Core provides a streamlined development experience.

Why Choose ASP.NET Core?

First Project – Hello World

Open a terminal and run the following commands:


dotnet new webapp -o MyFirstApp
cd MyFirstApp
dotnet run
        

Navigate to http://localhost:5000 in your browser. You should see the default Razor Pages template.

Key Files Explained

Sample Controller

Below is a simple API controller returning JSON data:


using Microsoft.AspNetCore.Mvc;

namespace MyFirstApp.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing","Bracing","Chilly","Cool","Mild","Warm","Balmy","Hot","Sweltering","Scorching"
        };

        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            return Enumerable.Range(1,5).Select(index => new WeatherForecast
            {
                Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                TemperatureC = Random.Shared.Next(-20,55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }
    }

    public record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary);
}
        

Access it at http://localhost:5000/api/weatherforecast.

Comments