Introducing ASP.NET Web Pages
ASP.NET Web Pages is one of three programming models Microsoft ships under the ASP.NET umbrella, alongside Web Forms and MVC. Unlike Web Forms, which relies on a heavy page lifecycle, server controls, and ViewState, Web Pages lets you build a site as a folder of .cshtml or .vbhtml files where server-side code and HTML markup live side by side. Each file maps directly to a URL, so there is no separate routing configuration or controller layer to set up before you can see a page render in the browser.
Cricket analogy: Web Pages is like a club-level net session where a batter like a young Shubman Gill just walks in and faces bowling without the full ceremony of a Test match toss, fielding plan, and DRS reviews that Web Forms would demand.
Who Web Pages Is For
Microsoft designed Web Pages for hobbyists, students, and small-business developers who want to build a dynamic site quickly without learning the MVC pattern or the Web Forms control model. It ships as part of the free WebMatrix tooling and can also be used inside Visual Studio. Typical use cases include small brochure sites with a contact form, simple blogs, and internal tools where a database-backed page needs to display and accept data without the ceremony of routes, controllers, and views that ASP.NET MVC requires.
Cricket analogy: This targets the gully cricket player who just wants to bowl a few overs with a tennis ball on a lane, not the BCCI-contracted player who trains under a full support staff at the National Cricket Academy.
A First Web Pages File
@{
var greeting = "Hello, ASP.NET Web Pages!";
var visitCount = 1;
if (IsPost)
{
visitCount = Convert.ToInt32(Request["count"]) + 1;
}
}
<!DOCTYPE html>
<html>
<head><title>My First Page</title></head>
<body>
<h1>@greeting</h1>
<form method="post">
<input type="hidden" name="count" value="@visitCount" />
<button type="submit">Refresh count</button>
</form>
<p>You have refreshed @visitCount times.</p>
</body>
</html>In the example above, the file named Default.cshtml is both the code-behind and the markup in one place. The @{ } block at the top runs server-side C# before the HTML renders, and inline @variable expressions inject values directly into the markup. The IsPost property tells you whether the current request is a form submission, letting a single file handle both the initial GET request and any subsequent POST without a separate handler class, which is a stark contrast to the Page_Load event and separate .aspx.cs file that Web Forms requires.
Cricket analogy: IsPost acts like an umpire checking whether a ball was already bowled in the over, similar to how Jasprit Bumrah's run-up before a no-ball check determines whether the delivery counts, letting the same over handle multiple states.
ASP.NET Web Pages files use the .cshtml extension for C# or .vbhtml for Visual Basic. The file name itself becomes part of the URL, so Contact.cshtml is reachable at /Contact with no routing configuration needed.
Web Pages vs. Web Forms and MVC
Web Forms centers on a page lifecycle with events like Page_Load, server controls such as GridView and Button that maintain state via ViewState, and a strict separation between markup (.aspx) and code-behind (.aspx.cs). MVC introduces controllers, models, and views with explicit routing and a testable separation of concerns. Web Pages sits deliberately below both in complexity: there is no page lifecycle to learn, no ViewState, and no controller classes, which makes it approachable for beginners but less structured for large applications with many contributors.
Cricket analogy: Web Forms is like Test cricket with five days, multiple sessions, and detailed field placements, MVC is like a well-drilled T20 franchise strategy, and Web Pages is like an over of gully cricket where you just play the ball as it comes.
Web Pages is not intended for large, multi-developer enterprise applications. Because it lacks the enforced separation of concerns that MVC provides, mixing significant business logic into .cshtml files can quickly become hard to test and maintain as a project grows.
- ASP.NET Web Pages is a lightweight programming model that mixes C#/VB.NET code with HTML in .cshtml/.vbhtml files.
- Each file maps directly to a URL, so no separate routing layer is required.
- It is designed for beginners, hobbyists, and small sites rather than large enterprise applications.
- The IsPost property lets a single file handle both GET and POST requests without separate handler classes.
- Web Pages avoids the page lifecycle, server controls, and ViewState that Web Forms relies on.
- Compared to MVC, Web Pages has no controllers or enforced separation of concerns, trading structure for simplicity.
- WebMatrix and Visual Studio both support developing ASP.NET Web Pages sites.
Practice what you learned
1. What file extension does an ASP.NET Web Pages file use for C# code?
2. How does a Web Pages file typically become reachable as a URL?
3. What does the IsPost property indicate inside a .cshtml file?
4. Which of the following is most true about ASP.NET Web Pages compared to MVC?
5. Who is ASP.NET Web Pages primarily designed for?
Was this page helpful?
You May Also Like
Razor Syntax in Web Pages
A practical guide to the Razor markup syntax that lets you embed C# or VB.NET code inline with HTML using the @ symbol, including expressions, code blocks, loops, and conditionals.
WebMatrix and Project Structure
How Microsoft's free WebMatrix tool creates and organizes an ASP.NET Web Pages site, including the special App_Data, App_Start, and Account folders and the built-in development web server.
Helpers in Web Pages
How built-in and custom helpers provide reusable, prebuilt pieces of functionality, from Chart and WebGrid to WebMail and Facebook integration, plus how to write your own helper with @helper.
Layout Pages in Web Pages
How shared layout pages, the RenderBody and RenderSection methods, and reusable partial views let ASP.NET Web Pages sites keep a consistent header, footer, and navigation across many content pages.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics