This module is where your C# logic meets the internet. ASP.NET Core is Microsoft’s modern, cross-platform, high-performance framework for building cloud-based, internet-connected applications.
ASP.NET Core is a complete redesign of the older ASP.NET 4.x. It is built to be fast, modular, and run anywhere (Windows, macOS, Linux).
If you see tutorials from before 2016, they likely refer to “Classic” ASP.NET. Here is how they differ:
| Feature | ASP.NET MVC (Classic) | ASP.NET Core |
| Hosting | Requires IIS (Windows Only) | Self-hosted (Kestrel) or IIS, Nginx, Apache |
| Dependencies | Included in the .NET Framework | Shipped as NuGet packages (Modular) |
| Configuration | Web.config (XML) | appsettings.json (JSON) |
| Dependency Injection | Requires 3rd party (Autofac, Ninject) | Built-in by default |
When you create a new ASP.NET Core Web API or Web App, the structure looks like this:
Program.cs: The entry point. It sets up the Web Host, configures services (DI), and defines the request pipeline.appsettings.json: Where you store connection strings and environment-specific settings.wwwroot: (For Web Apps) Stores static files like CSS, JS, and images.Controllers/: Where the logic for handling HTTP requests lives.The Lifecycle:
Middleware are software components assembled into an application pipeline to handle requests and responses.
UseRouting(), UseAuthentication(), UseStaticFiles(), and UseExceptionHandler().Routing is how the framework maps an incoming URL (e.g., /products/5) to a piece of code.
You place attributes directly on the Controller or Action.
C#
[ApiController]
[Route("api/[controller]")] // Routes to /api/products
public class ProductsController : ControllerBase {
[HttpGet("{id}")] // Routes to /api/products/5
public IActionResult GetProduct(int id) { ... }
}
Defined globally in Program.cs. It follows a pattern like {controller=Home}/{action=Index}/{id?}.
ControllerBase (for APIs) or Controller (for Web Apps with Views).IActionResult.
Ok() -> Returns 200 Success.NotFound() -> Returns 404.BadRequest() -> Returns 400.This is the “magic” that takes data from the URL, Form, or JSON Body and turns it into a C# object.
{"Name": "Laptop"} to an action expecting a Product object, ASP.NET Core automatically maps the fields.public class Product { [Required] [StringLength(50)] public string Name { get; set; } [Range(1, 1000)] public decimal Price { get; set; } } If the user sends a price of -5, the framework can automatically return a 400 Bad Request before your code even runs.By the end of this module, you should be able to:
Postman or Swagger to send data to your app and see the JSON response.