Net 5TH Unit
Net 5TH Unit
2. ASP.NET Architecture
ASP.NET follows a layered architecture consisting of three primary layers:
1. Presentation Layer:
o Manages the user interface using Web Forms or Razor Pages.
o Includes components like HTML, CSS, JavaScript, and server controls.
2. Business Logic Layer (BLL):
o Contains the application’s core logic.
o Processes user inputs and interacts with the database.
3. Data Access Layer (DAL):
o Handles data operations such as retrieval and manipulation.
o Communicates with databases using ADO.NET or Entity Framework.
Request-Response Flow:
1. Client sends a request to the server.
2. ASP.NET processes the request using HTTP handlers.
3. Server-side controls and code generate a response.
4. Response is sent back to the client.
3. Web Forms
Web Forms are a part of the ASP.NET framework that allows developers to create dynamic,
data-driven web applications.
Key Components:
o .aspx File: Contains the HTML markup and server-side controls.
o Code-Behind File: Contains the server-side logic written in C# or VB.NET.
Example:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Default" %>
<!DOCTYPE html>
<html>
<head>
<title>ASP.NET Web Form</title>
</head>
<body>
<form runat="server">
<asp:Label ID="Label1" runat="server" Text="Hello, World!"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Click Me" OnClick="Button1_Click"
/>
</form>
</body>
</html>
4. Web Servers
A web server processes HTTP requests and serves web pages to clients.
Types of Web Servers in ASP.NET:
o IIS (Internet Information Services):
Developed by Microsoft, highly compatible with ASP.NET.
o Kestrel:
Lightweight cross-platform server for .NET Core applications.
o Apache and Nginx:
Can host ASP.NET applications via reverse proxy.
5. Server Controls in ASP.NET
ASP.NET provides a wide variety of server controls that simplify web development.
Types of Server Controls:
1. HTML Server Controls: Enhanced HTML controls with server-side
processing capabilities.
2. Web Server Controls: Includes advanced controls like GridView,
DropDownList, Calendar, etc.
3. Validation Controls: For client-side and server-side validation (e.g.,
RequiredFieldValidator).
Example:
Using a DropDownList:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="Option 1" Value="1"></asp:ListItem>
<asp:ListItem Text="Option 2" Value="2"></asp:ListItem>
</asp:DropDownList>
7. Introduction to XML
XML (eXtensible Markup Language) is a widely used format for data storage and exchange.
Features of XML:
o Platform-independent.
o Self-descriptive and hierarchical.
o Used for data interchange in web services.
Example of XML Document:
<Students>
<Student>
<Name>John Doe</Name>
<Age>22</Age>
</Student>
<Student>
<Name>Jane Smith</Name>
<Age>21</Age>
</Student>
</Students>
student.AppendChild(name);
student.AppendChild(age);
root.AppendChild(student);
doc.AppendChild(root);
doc.Save(Server.MapPath("Students.xml"));
}
Summary
ASP.NET provides a powerful framework for building dynamic web applications with
features like Web Forms, server controls, and data connectivity.
XML is an integral part of ASP.NET for data storage and exchange.
Combined with ADO.NET, ASP.NET simplifies database interactions.