MSDN Documentation

.NET Web Applications

Understanding .NET Web Applications

.NET provides a robust and versatile platform for building modern web applications. From simple websites to complex enterprise-level applications and single-page applications, .NET offers a rich set of tools, frameworks, and libraries to streamline development, enhance performance, and ensure security.

ASP.NET Core: The Modern Framework

ASP.NET Core is the successor to ASP.NET, a high-performance, cross-platform, open-source framework for building cloud-ready, internet-connected applications. It unifies the existing .NET frameworks into a single framework that runs on Windows, macOS, and Linux.

  • Cross-Platform: Develop and run your web applications on any operating system.
  • High Performance: Optimized for speed and efficiency.
  • Modular Design: Built with dependency injection at its core.
  • Open Source: Transparent development and community contributions.

Model-View-Controller (MVC) Pattern

ASP.NET Core MVC is a popular framework for building dynamic websites. It implements the MVC architectural pattern, which separates an application into three interconnected components:

  1. Model: Represents the data and business logic of the application.
  2. View: Handles the presentation logic, displaying data to the user.
  3. Controller: Acts as an intermediary, handling user input, interacting with the model, and selecting a view to render.

Basic MVC Controller Example


using Microsoft.AspNetCore.Mvc;

public class HomeController : Controller
{
    public IActionResult Index()
    {
        ViewBag.Message = "Welcome to our ASP.NET Core MVC Application!";
        return View();
    }

    public IActionResult About()
    {
        ViewBag.Message = "Your application description page.";
        return View();
    }
}
                    

Razor Pages: Simpler Page-Centric Development

Razor Pages is an alternative page-focused programming model within ASP.NET Core. It simplifies building Razor UI for web applications by focusing on pages rather than controllers. It's ideal for scenarios where you need a straightforward way to build server-rendered HTML.

Each page consists of a Razor file (.cshtml) and a C# code-behind file (.cshtml.cs).

Razor Page Example (.cshtml)


@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

Welcome

@Model.Message

Razor Page Model Example (.cshtml.cs)


using Microsoft.AspNetCore.Mvc.RazorPages;

public class IndexModel : PageModel
{
    public string Message { get; set; }

    public void OnGet()
    {
        Message = "This is a Razor Page.";
    }
}
                    

Building Web APIs with ASP.NET Core

ASP.NET Core makes it easy to build robust and scalable Web APIs using HTTP. These APIs can be consumed by a wide range of clients, including web browsers, mobile apps, and other services. You can create RESTful services that return data in formats like JSON or XML.

Blazor: Modern Web UI with .NET

Blazor is a revolutionary framework that allows developers to build interactive client-side web UI with .NET and C#. It enables full-stack web development using C# for both the front-end and back-end.

  • Blazor Server: Runs your app UI entirely in the browser, while the server handles execution.
  • Blazor WebAssembly (WASM): Runs your app UI entirely in the browser on a WebAssembly-based .NET runtime.

Hosting and Deployment

ASP.NET Core applications can be hosted in various environments:

  • IIS: Internet Information Services on Windows.
  • Kestrel: ASP.NET Core's built-in cross-platform web server.
  • Docker: Containerization for consistent deployments.
  • Cloud Platforms: Azure App Service, AWS Elastic Beanstalk, Google App Engine, and more.

Deployment options include self-contained deployments or framework-dependent deployments.