0% found this document useful (0 votes)
11 views6 pages

Net 5TH Unit

Unit 5 of .net

Uploaded by

ixiixi439
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Net 5TH Unit

Unit 5 of .net

Uploaded by

ixiixi439
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIT-5

ASP.NET is a web development framework developed by Microsoft for building dynamic


web applications and services. It is part of the .NET Framework and provides a robust
platform for developing scalable and secure web applications.
 Key Features:
o Supports server-side scripting.
o Built-in support for authentication and authorization.
o Provides tools for state management (Session, Application, ViewState).
o Integration with ADO.NET for database connectivity.
o Supports various protocols such as HTTP, HTTPS, and more.
o Highly secure and scalable.

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>

6. Data Connectivity Using ASP.NET


Data connectivity in ASP.NET is achieved using ADO.NET, which provides a set of classes
for working with databases.
 Key Components:
1. SqlConnection: Establishes a connection to the database.
2. SqlCommand: Executes SQL queries and stored procedures.
3. SqlDataAdapter: Fills data into DataSet or DataTable.
4. SqlDataReader: Provides forward-only data retrieval.
Example:
Connecting to a Database and Displaying Data in GridView:
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
string connectionString = "your_connection_string";
using (SqlConnection conn = new SqlConnection(connectionString)) {
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Students", conn);
DataTable dt = new DataTable();
adapter.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}

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>

8. Using XML with ASP.NET


ASP.NET provides tools for working with XML, such as XmlReader, XmlWriter, and LINQ
to XML.
Examples:
Reading an XML File:
using System.Xml;

protected void ReadXML() {


XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("Students.xml"));
foreach (XmlNode node in doc.DocumentElement.ChildNodes) {
string name = node["Name"].InnerText;
string age = node["Age"].InnerText;
Response.Write($"Name: {name}, Age: {age}<br>");
}
}
Writing to an XML File:
using System.Xml;

protected void WriteXML() {


XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("Students");
XmlElement student = doc.CreateElement("Student");

XmlElement name = doc.CreateElement("Name");


name.InnerText = "New Student";
XmlElement age = doc.CreateElement("Age");
age.InnerText = "23";

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.

You might also like