Note: This is a reference page with static code examples. ASP.NET requires Windows Server with IIS and the .NET runtime, which is not configured on this server.
Overview
Released: 2002 by Microsoft
File Extensions: .aspx (Web Forms), .cshtml (Razor), .cs (code-behind)
Server Required: IIS on Windows (or Kestrel for .NET Core/5+)
Languages: C#, VB.NET, F#
ASP.NET was Microsoft's complete reimagining of web development, replacing Classic ASP with a compiled, object-oriented framework built on the .NET Common Language Runtime. It introduced concepts like code-behind files, server controls, and ViewState that abstracted away much of the HTTP request/response cycle.
The framework has evolved significantly: ASP.NET Web Forms (2002), ASP.NET MVC (2009), ASP.NET Web API (2012), and ASP.NET Core (2016). Modern development typically uses ASP.NET Core with Razor Pages or MVC, which runs cross-platform on Windows, Linux, and macOS.
Hello World (Web Forms)
Traditional ASP.NET Web Forms use .aspx files with server controls:
<%@ Page Language="C#" %>
<!DOCTYPE html>
<html>
<head>
<title>Hello, ASP.NET!</title>
</head>
<body>
<h1>Hello, ASP.NET!</h1>
<p>This page was generated with ASP.NET Web Forms</p>
<p>Current time: <%= DateTime.Now %></p>
<p>Your IP: <%= Request.UserHostAddress %></p>
</body>
</html>
Hello World (Razor Pages)
Modern ASP.NET Core uses Razor syntax with .cshtml files:
@page
@model IndexModel
<!DOCTYPE html>
<html>
<head>
<title>Hello, ASP.NET Core!</title>
</head>
<body>
<h1>Hello, ASP.NET Core!</h1>
<p>Current time: @DateTime.Now</p>
<p>Your IP: @HttpContext.Connection.RemoteIpAddress</p>
</body>
</html>
Environment Variables
ASP.NET provides rich access to request and server information:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections" %>
<h2>Request Headers</h2>
<%
foreach (string key in Request.Headers.AllKeys) {
Response.Write("<b>" + key + ":</b> " + Request.Headers[key] + "<br>");
}
%>
<h2>Server Variables</h2>
<p><b>Server Name:</b> <%= Request.ServerVariables["SERVER_NAME"] %></p>
<p><b>Server Port:</b> <%= Request.ServerVariables["SERVER_PORT"] %></p>
<p><b>Request Method:</b> <%= Request.HttpMethod %></p>
Form Handling (GET)
Query parameters are accessed via Request.QueryString:
<%@ Page Language="C#" %>
<%
string name = Request.QueryString["name"];
if (!String.IsNullOrEmpty(name)) {
%>
<p>Hello, <%= Server.HtmlEncode(name) %>!</p>
<%
} else {
%>
<p>No name provided</p>
<%
}
%>
Form Handling (POST)
POST data is accessed via Request.Form:
<%@ Page Language="C#" %>
<%
if (Request.HttpMethod == "POST") {
string username = Request.Form["username"];
string email = Request.Form["email"];
%>
<p>Username: <%= Server.HtmlEncode(username) %></p>
<p>Email: <%= Server.HtmlEncode(email) %></p>
<%
}
%>
Sessions
ASP.NET provides built-in session management via the Session object:
<%@ Page Language="C#" %>
<%
Session["username"] = Request.Form["username"];
string savedName = Session["username"] as string;
Session.Remove("username");
Session.Clear();
Session.Abandon();
%>
Code-Behind Pattern
ASP.NET popularized separating markup from logic with code-behind files:
Default.aspx:
<%@ Page Language="C#" CodeBehind="Default.aspx.cs" Inherits="MyApp.DefaultPage" %>
<html>
<body>
<form runat="server">
<asp:Label ID="lblMessage" runat="server"/>
<asp:Button ID="btnSubmit" Text="Click Me"
OnClick="btnSubmit_Click" runat="server"/>
</form>
</body>
</html>
Default.aspx.cs:
using System;
namespace MyApp {
public partial class DefaultPage : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
lblMessage.Text = "Welcome!";
}
}
protected void btnSubmit_Click(object sender, EventArgs e) {
lblMessage.Text = "Button clicked at " + DateTime.Now;
}
}
}
ASP.NET Core Minimal API
Modern ASP.NET Core supports minimal APIs for simple services:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello, ASP.NET Core!");
app.MapGet("/hello/{name}", (string name) => $"Hello, {name}!");
app.MapPost("/api/data", (DataModel data) => Results.Ok(data));
app.Run();
Evolution: ASP.NET has transformed dramatically. Web Forms with ViewState is considered legacy. Modern .NET development uses ASP.NET Core with Razor Pages, MVC, Blazor (WebAssembly), or minimal APIs. ASP.NET Core runs cross-platform and in containers.
← Back to Home