MSDN Documentation

ASP.NET Getting Started Tutorial

Welcome to the official Microsoft tutorial for building your first ASP.NET Web Forms application using the .NET Framework. This step‑by‑step guide walks you through creating a simple web app, from project setup to deployment.

Table of Contents Overview Prerequisites Step 1 – Create Project Step 2 – Build UI Step 3 – Add Logic Step 4 – Deploy Additional Resources

Overview

This tutorial demonstrates how to:

  • Set up a new ASP.NET Web Forms project in Visual Studio.
  • Design a responsive UI using Bootstrap.
  • Implement server‑side logic with C#.
  • Test and debug the application locally.
  • Publish the site to IIS.

Prerequisites

Before you begin, ensure you have the following installed:

  • Visual Studio 2022 (Community or higher) with .NET desktop development workload.
  • .NET Framework 4.8 SDK.
  • IIS Express (installed with Visual Studio).

Optional: Git for source control.

Step 1 – Create Project

Open Visual Studio and follow these steps:

  1. Click File → New → Project.
  2. Select ASP.NET Web Application (.NET Framework) and click Next.
  3. Enter GettingStartedWebApp as the project name and choose a location.
  4. Choose the Web Forms template and ensure Enable Docker Support is unchecked.
  5. Click Create.
// No code needed for project creation; Visual Studio handles it.

Step 2 – Build UI

Add a simple page that displays a greeting and a form.

  1. Right‑click the project, choose Add → Web Form, name it Default.aspx.
  2. Replace the markup with the following:
<!DOCTYPE html> <html lang="en"> <head runat="server"> <meta charset="utf-8" /> <title>Getting Started</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <form id="form1" runat="server" class="container py-5"> <div class="row"> <div class="col-md-6 offset-md-3"> <h2 class="mb-4">Hello, ASP.NET!</h2> <asp:Label ID="lblMessage" runat="server" CssClass="form-label">Enter your name:</asp:Label> <asp:TextBox ID="txtName" runat="server" CssClass="form-control mb-3"></asp:TextBox> <asp:Button ID="btnGreet" runat="server" Text="Greet Me" CssClass="btn btn-primary" OnClick="BtnGreet_Click" /> <asp:Literal ID="ltResult" runat="server" EnableViewState="false" /> </div> </div> </form> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> </body> </html>

Save the file and build the project (Ctrl+Shift+B).

Step 3 – Add Logic

Open Default.aspx.cs and implement the click handler:

using System; using System.Web.UI; public partial class _Default : Page { protected void BtnGreet_Click(object sender, EventArgs e) { string name = txtName.Text.Trim(); if (string.IsNullOrEmpty(name)) { ltResult.Text = "<div class='alert alert-warning mt-3'>Please enter a name.</div>"; } else { ltResult.Text = $"<div class='alert alert-success mt-3'>Hello, {Server.HtmlEncode(name)}!</div>"; } } }

Run the application (F5). The page should now greet the user.

Step 4 – Deploy

To publish the app to IIS:

  1. Right‑click the project → Publish....
  2. Select Folder as the target and choose a location (e.g., C:\inetpub\wwwroot\GettingStartedWebApp).
  3. Click Finish, then Publish.
  4. Open the IIS Manager, add a new website pointing to the published folder.
  5. Browse to http://localhost/GettingStartedWebApp to see the live site.

Congratulations! Your first ASP.NET Web Forms app is live.

Additional Resources