Unit - V ( Hinglish Version )

ASP.NET Introduction

ASP.NET ek web application framework hai jo Microsoft ne develop kiya hai dynamic websites, web applications, aur web services banane ke liye. Ye .NET Framework ka part hai aur robust, scalable server-side applications create karne ke liye use hota hai.

ASP.NET Features

  1. Cross-Platform: Windows, macOS, aur Linux par support karta hai (with .NET Core).

  2. State Management: Session aur application states ko effectively manage karta hai.

  3. Security: Authentication aur authorization ke liye built-in support.

  4. Rich Controls: Server-side controls ke saath dynamic UI banane ka option.

  5. Data Access: Database connectivity ke liye ADO.NET use karta hai.

  6. Performance: Compiled code use karta hai, jo interpreted frameworks se zyada fast hota hai.


ASP.NET Architecture

ASP.NET architecture ka base Common Language Runtime (CLR) hai aur ye layered structure follow karta hai:

  1. User Interface Layer:

    • Web Forms aur Razor Pages ke through UI define kiya jata hai.

  2. Application Layer:

    • Business logic ko handle karta hai jaise requests process karna aur user interactions.

  3. Data Layer:

    • ADO.NET ya Entity Framework ka use karke database se interact karta hai.

  4. HTTP Pipeline:

    • HTTP requests aur responses ko modules aur handlers ke through process karta hai.


Web Forms

Web Forms ek page-centric programming model hai jo dynamic aur interactive web pages banane ke liye use hota hai. Ye HTML, CSS aur server-side code ka mix hai.

Web Form Structure:

  • Code-Behind File: Server-side logic ko store karta hai (C# ya VB.NET me likha hota hai).

  • ASPX File: Markup aur server controls ke saath UI define karta hai.

Example of a Simple Web Form:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyApp.Default" %>  
<!DOCTYPE html>  
<html>  
<head>  
    <title>Simple Form</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
        <asp:Label ID="Label1" runat="server" Text="Enter Name: "></asp:Label>  
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
        <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />  
    </form>  
</body>  
</html>  

Web Servers

Web server wo system hai jo web applications ko host karta hai aur users ko deliver karta hai. HTTP requests process karta hai aur responses generate karta hai.

ASP.NET Ke Liye Common Web Servers:

  1. IIS (Internet Information Services):

    • Windows ke liye default web server.

  2. Kestrel:

    • Lightweight aur cross-platform web server.

  3. Apache ya Nginx:

    • Reverse proxy ke liye Kestrel ke saath use hota hai.


Server Controls in ASP.NET

Server controls reusable components hote hain jo web development ko simplify karte hain. Ye UI render karte hain aur events handle karte hain.

Types of Server Controls:

  1. HTML Controls:

    • Basic HTML elements with runat="server".

    <input type="text" runat="server" id="txtName" />  
  2. ASP.NET Controls:

    • Predefined controls jaise TextBox, Label, aur Button.

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
  3. Data Controls:

    • Data ko bind karte hain UI ke saath (GridView, DataList).

  4. Validation Controls:

    • User inputs validate karte hain (e.g., RequiredFieldValidator).

Example of Validation Control:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
<asp:RequiredFieldValidator ControlToValidate="TextBox1" ErrorMessage="Field is required" runat="server" />  

Data Connectivity Using ASP.NET

ASP.NET data ko database se connect karne ke liye ADO.NET ka use karta hai.

Database Connection Example:

using System.Data.SqlClient;  

SqlConnection conn = new SqlConnection("your_connection_string");  
conn.Open();  
SqlCommand cmd = new SqlCommand("SELECT * FROM Users", conn);  
SqlDataReader reader = cmd.ExecuteReader();  

while (reader.Read())  
{  
    Console.WriteLine(reader["Name"]);  
}  

conn.Close();  

Introduction to XML

XML (eXtensible Markup Language) ek markup language hai jo data ko store aur transport karne ke liye use hoti hai.

XML Features:

  1. Platform Independent: Kisi bhi system ke saath compatible.

  2. Hierarchical Structure: Data tree-like structure me organize hota hai.

  3. Self-Descriptive: Tags meaningful context dete hain.


Using XML with ASP.NET

ASP.NET me XML ka use alag-alag purposes ke liye hota hai:

  1. Web.config: Application settings aur configurations ke liye.

  2. Data Storage: Lightweight alternative to databases.

  3. Data Exchange: APIs ke liye data exchange karne ke liye.

Reading XML in ASP.NET:

using System.Xml;  

XmlDocument doc = new XmlDocument();  
doc.Load("data.xml");  
XmlNodeList nodes = doc.SelectNodes("//User");  

foreach (XmlNode node in nodes)  
{  
    Console.WriteLine(node["Name"].InnerText);  
}  

Writing XML in ASP.NET:

using System.Xml;  

XmlDocument doc = new XmlDocument();  
XmlElement user = doc.CreateElement("User");  
user.SetAttribute("Id", "1");  

XmlElement name = doc.CreateElement("Name");  
name.InnerText = "John Doe";  
user.AppendChild(name);  

doc.AppendChild(user);  
doc.Save("data.xml");  

Summary

  1. ASP.NET: Robust framework for dynamic web applications.

  2. Web Forms: Dynamic pages ke liye page-centric model.

  3. Web Servers: Applications host karte hain, jaise IIS.

  4. Server Controls: UI aur events simplify karte hain.

  5. Data Connectivity: Database ke saath seamless integration.

  6. XML: Configuration aur data exchange ke liye.

Last updated