## Introduction to ASP.NET
ASP.NET is a robust, unified web development platform developed by Microsoft. It provides the programming model, software infrastructure, and essential services required to build secure, enterprise-class web applications.
To understand ASP.NET, it is helpful to look at its evolution from Classic ASP to the modern .NET ecosystem.
---
## Classic ASP vs. ASP.NET
### Classic ASP (Active Server Pages)
Introduced in 1998 as Microsoft's first server-side scripting engine, Classic ASP allows scripts to be executed on an internet server.
* **File Extension:** `.asp`
* **Primary Language:** VBScript
* **Execution:** Interpreted line-by-line, which limits performance compared to compiled alternatives.
### ASP.NET
ASP.NET is the successor to Classic ASP. It is not backward-compatible with Classic ASP, though they can run side-by-side on the same server.
* **File Extension:** `.aspx`
* **Primary Languages:** C# (C-Sharp) or VB.NET (Visual Basic .NET)
* **Execution:** Compiled. Because ASP.NET pages are compiled into intermediate language (IL) and then compiled to native code, they execute significantly faster than Classic ASP.
* **Key Features:** Rich language support, a vast library of reusable user controls, XML-based configuration, built-in security, and integrated user authentication.
---
## How ASP.NET Works
When a client browser requests an ASP.NET file (such as an `.aspx` page), the execution flow proceeds as follows:
```
β
βΌ
[Web Server (IIS)] βββΊ [ASP.NET Engine] (Reads, compiles, and executes server-side code)
β
βΌ
βββ [Plain HTML/CSS/JS Output]
```
1. The browser sends a request for an `.aspx` file to the web server.
2. The **ASP.NET Engine** intercepts the request, reads the file, compiles the server-side code, and executes the business logic.
3. The engine renders the final output as standard **HTML, CSS, and JavaScript**, which is sent back to the browser. The client browser never sees the original server-side C# or VB.NET code.
---
## ASP.NET Server Technologies
Over its lifecycle, ASP.NET has supported three primary development models:
### 1. Web Pages (Razor Syntax)
A lightweight, single-page model that mixes server code directly with HTML. It uses **Razor syntax**, which is clean, fast, and easy to learn.
* **File Extensions:** `.cshtml` (for C#) and `.vbhtml` (for Visual Basic)
### 2. MVC (Model-View-Controller)
A highly structured design pattern that separates an application into three main components:
* **Model:** Represents the application data and business logic.
* **View:** Displays the data (the user interface).
* **Controller:** Handles user input and coordinates interactions between the Model and the View.
This model offers clean separation of concerns, making it ideal for large-scale, testable enterprise applications.
### 3. Web Forms
The traditional, event-driven ASP.NET model. It mimics desktop application development by using reusable UI controls (like buttons and text boxes) that maintain state across HTTP requests using a mechanism called ViewState.
* **File Extension:** `.aspx`
---
## Programming Languages
ASP.NET applications are written using fully-featured object-oriented programming languages. The two most common are:
* **C# (pronounced "C-Sharp"):** The industry-standard language for modern .NET development.
* **Visual Basic .NET (VB.NET):** A modern, object-oriented version of Visual Basic.
Additionally, custom controls and backend services in ASP.NET can be written in other .NET-compliant languages, including C++ and F#.
---
## File Extension Reference
| Extension | Technology | Description |
| :--- | :--- | :--- |
| `.asp` | Classic ASP | Legacy server-side scripting files, typically written in VBScript. |
| `.aspx` | ASP.NET Web Forms | Compiled web pages containing Web Forms controls and markup. |
| `.cshtml` | ASP.NET Razor (C#) | Web pages using Razor syntax with C# server-side code. |
| `.vbhtml` | ASP.NET Razor (VB) | Web pages using Razor syntax with Visual Basic server-side code. |
---
## Development Tools
ASP.NET applications can be built using several development environments:
* **Visual Studio:** Microsoft's flagship, full-featured Integrated Development Environment (IDE) for professional enterprise development.
* **Visual Studio Code (VS Code):** A lightweight, cross-platform, open-source code editor widely used for modern ASP.NET Core development.
* **Visual Web Developer / WebMatrix:** Legacy, lightweight tools previously used for Web Forms and simple Razor Web Pages.
---
## Code Examples
### 1. Classic ASP Example (`.asp`)
This legacy script uses VBScript to output the current time:
```html
Classic ASP Example
<%
Response.Write("
The current server time is: " & Time() & "
")
%>
```
### 2. ASP.NET Razor Example (`.cshtml`)
This modern Razor example uses C# to display the current date and time cleanly inline:
```html
ASP.NET Razor Example
The current server time is: @DateTime.Now
```
---
## Key Considerations for Modern Developers
* **Legacy ASP.NET vs. ASP.NET Core:** Traditional ASP.NET (versions 1.0 through 4.x) is tied exclusively to the Windows operating system and Internet Information Services (IIS). Modern development has shifted to **ASP.NET Core**, which is a completely rewritten, open-source, and cross-platform framework that runs on Windows, macOS, and Linux.
* **Performance:** Always leverage compiled models (like MVC or Razor Pages) over legacy interpreted scripts to ensure optimal server response times and resource utilization.