ASP.NET — Study Notes

Unit 3 & 4

ADO.NET, State Management, and Web Services

27 Questions 2 & 5 Marks Combined Units
01
2 Marks Question

What is ADO.NET? State its Features.

ADO.NET (ActiveX Data Objects .NET) is a data access technology in the .NET Framework used to connect applications with databases, execute queries, and retrieve or manipulate data. It supports both connected and disconnected data access modes.

Features

  • 01Supports connected and disconnected data access.
  • 02Works with databases such as SQL Server, Oracle, MySQL, and Access.
  • 03Supports XML natively through DataSet.
  • 04Provides classes for database connection, commands, reading, and updating data.
  • 05Uses namespaces such as System.Data and System.Data.SqlClient.
02
2 Marks Question

What are Data Provider, DataSet and DataAdapter?

Data Provider
A set of classes designed to connect and work with a specific database. Examples include SqlClient for SQL Server, OleDb for Access/Excel, and Odbc for ODBC databases.
DataSet
An in-memory representation of a relational database. It can contain multiple DataTables, relationships, rows, columns, and constraints, and can work without an active connection.
DataAdapter
Acts as a bridge between the database and DataSet. Uses Fill() to load data from the database into a DataSet and Update() to send changes back to the database.
03
2 Marks Question

What is the purpose of the CommandBuilder class?

CommandBuilder is an ADO.NET class used to automatically generate the SQL INSERT, UPDATE, and DELETE commands for a DataAdapter. It saves the programmer from writing these commands manually.

Example

SqlCommandBuilder cb = new SqlCommandBuilder(adapter);
adapter.Update(ds);
In short CommandBuilder simplifies CRUD operations when using a DataAdapter and DataSet.
04
2 Marks Question

What is DataReader? State its Use.

DataReader is an ADO.NET object used to read data from a database in connected mode. It provides fast, forward-only and read-only access to the result set.

Use

  • 01Used mainly for executing SELECT queries and reading records one by one.
  • 02The database connection must remain open while the DataReader is being used.
  • 03ExecuteReader() is used to obtain a DataReader.

Example

SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
    string name = dr["Name"].ToString();
}
05
2 Marks Question

Differentiate between ExecuteReader() and ExecuteNonQuery()

ExecuteReader()ExecuteNonQuery()
Used mainly for SELECT queries.Used mainly for INSERT, UPDATE, and DELETE queries.
Returns a DataReader containing the result set.Returns the number of rows affected.
Used when data needs to be read row by row.Used when data needs to be inserted, updated, or deleted.
Example:
SqlDataReader dr = cmd.ExecuteReader();
Example:
int rows = cmd.ExecuteNonQuery();
In short ExecuteReader() reads data, whereas ExecuteNonQuery() performs data modification operations.
06
2 Marks Question

What is Client-Server Communication in ASP.NET?

Client-server communication in ASP.NET is the process in which a web browser (client) sends a request to the ASP.NET server, and the server processes it and sends a response back.

Working

Browser (Client)
      ↓ HTTP Request
ASP.NET Web Server
      ↓
Process Request
      ↓
HTTP Response
      ↓
Browser (Client)

ASP.NET mainly uses two objects:

  • RequestReceives data sent by the browser, such as form values, query strings, cookies, and headers.
  • ResponseSends data from the server to the browser, such as HTML, redirects, cookies, and files.
Example: A user submits a form → browser sends an HTTP request → ASP.NET processes it → server sends the resulting HTML response back to the browser.
07
2 Marks Question

What are Request and Response Objects? State their Uses.

Request Object
Used to receive/read data sent from the browser to the ASP.NET server, such as form values, query strings, cookies, and headers.
Response Object
Used to send data from the ASP.NET server to the browser, such as HTML, redirects, cookies, and files.
In short Request = Client → Server
Response = Server → Client
08
2 Marks Question

What is a Cookie? Which object is used to read cookies?

A Cookie is a small piece of data stored on the client's browser by the web server. It is used for remembering information such as user preferences, login status, and session tracking.

The Request object is used to read/access cookies sent by the browser. The Response.Cookies collection is used to create or send cookies to the browser.

Example

string name = Request.Cookies["UserName"].Value;
09
2 Marks Question

What is a Query String? What is URL Encoding?

A Query String is data passed through the URL after a ? symbol. It is used to send small amounts of information from the client to the server.

Example

page.aspx?name=Riya&id=1

Here, name and id are query-string parameters.

URL Encoding is the process of converting special characters in a URL into a safe format so that they can be transmitted correctly.

10
2 Marks Question

What is Session State? Give an Example.

Session State is an ASP.NET state-management technique used to store user-specific data on the server and maintain it between different pages.

Session data is specific to each user.

Example

// Storing a value in session
Session["UserName"] = txtName.Text;

// Retrieving the value
string name = Session["UserName"].ToString();
11
2 Marks Question

What is Application State?

Application State is an ASP.NET state-management technique used to store data that is shared by all users throughout the entire application.

Example

Application["SiteVisitCount"] = 0;

It can be used for application-wide information such as a total visitor count.

12
2 Marks Question

What is State Management?

State Management is the technique of maintaining data and information between different requests/pages in an ASP.NET application.

Since HTTP is stateless, ASP.NET provides techniques such as ViewState, Session State, Application State, and Cookies to maintain state.

13
2 Marks Question

What is Web.config? Name its Important Sections.

Web.config is an ASP.NET configuration file used to store and manage application settings and configuration information.

Important Sections

<appSettings>
Stores application-specific settings.
<connectionStrings>
Stores database connection strings.
<system.web>
Contains ASP.NET settings such as session state, authentication, and compilation.
<system.webServer>
Contains IIS web-server configuration settings.
In short Web.config centralizes important ASP.NET application and server configuration settings.
14
2 Marks Question

Purpose of connectionStrings, appSettings and sessionState sections?

  • connectionStringsStores database connection strings used by the ASP.NET application.
  • appSettingsStores application-specific settings or key-value pairs.
  • sessionStateConfigures Session State, such as session mode and timeout.
15
2 Marks Question

What is SiteMapPath? What is Web.sitemap?

SiteMapPath
An ASP.NET navigation control that displays the current page's location in the website hierarchy, usually as a breadcrumb.
Example: Home > Products > Mobile
Web.sitemap
An XML file that defines the hierarchical structure of pages in an ASP.NET website. It provides the navigation information used by controls such as SiteMapPath.
16
2 Marks Question

What is Breadcrumb Navigation?

Breadcrumb navigation is a navigation technique that shows the current page's location within the website's hierarchy.

Example

Home > Products > Mobiles > Samsung

It helps users understand where they are on the website and easily navigate back to previous pages.

17
2 Marks Question

What is a Web Service? What is an ASMX Web Service?

A Web Service is a software component that allows applications to communicate and exchange data over a network.

An ASMX Web Service is a classic ASP.NET Web Service that uses the .asmx file extension. Its public methods are exposed to clients using the [WebMethod] attribute.

18
2 Marks Question

What is the Purpose of the <WebMethod> Attribute?

The [WebMethod] attribute is applied to a public method in an ASMX Web Service to make that method available as a Web Service operation, so that client applications can invoke it.

Example

[WebMethod]
public int Add(int a, int b)
{
    return a + b;
}

Here, Add() can be called by a client application as a Web Service method.

19
2 Marks Question

What are SOAP and WSDL?

SOAP (Simple Object Access Protocol)
A protocol/message framework used for communication between a client and a Web Service. It allows messages to be exchanged over HTTP.
WSDL (Web Services Description Language)
An XML document that describes a Web Service, including its available operations, parameters, return values, and communication information. Commonly accessed using ?wsdl.
In short SOAP = How messages are exchanged.
WSDL = What the Web Service provides and how to communicate with it.
20
2 Marks Question

What is a Proxy Class in Web Services?

A Proxy Class is a client-side class generated from the Web Service description (WSDL). It acts as a local representative of the remote Web Service, allowing the client application to call its methods as if they were local methods.

Flow

Web Service → WSDL → Proxy Class → Client Application

The proxy is generated when the client adds a Web Reference/Service Reference to the Web Service.

21
2 Marks Question

What is Meant by Consuming a Web Service?

Consuming a Web Service means using a Web Service from a client application by connecting to the service and calling its available methods.

Basic Process

Web Service
     ↓
   WSDL
     ↓
Proxy Class
     ↓
Client Application
     ↓
Call Web Service Method

In ASP.NET, the client adds a Web Reference/Service Reference, obtains the WSDL, generates a proxy class, and then uses the proxy to call the required Web Service methods.

Example

StudentWS.StudentService svc = new StudentWS.StudentService();
int result = svc.Add(10, 20);

Here, the client is consuming the StudentService Web Service by calling its Add() method.

5 Marks Questions
01
5 Marks Question

Explain ADO.NET Architecture. Differentiate between Connected and Disconnected Data Models.

ADO.NET (ActiveX Data Objects .NET) is a data-access technology in the .NET Framework. It provides classes for connecting to databases, executing commands, and retrieving/manipulating data using both connected and disconnected modes.

Diagram Note: Draw the ADO.NET Architecture diagram from Page 5 of your Unit 3 notes in the exam. It shows .NET Framework Data Provider, Connection, Command, DataReader, DataAdapter, DataSet, DataTable, DataRelationCollection, and Database/XML.

Components of ADO.NET

01
Data Provider

A set of classes designed for a particular database. Examples: SqlClient → SQL Server, OleDb → MS Access/Excel.

02
Connection

Establishes and manages the physical connection between the app and the database. Important methods are Open() and Close().

03
Command

Executes SQL queries or stored procedures. Important methods: ExecuteReader(), ExecuteNonQuery(), ExecuteScalar().

04
DataReader

Provides a fast, forward-only and read-only stream of data. Requires the database connection to remain open.

05
DataAdapter

Bridge between the database and DataSet. Fill() loads data; Update() sends changes back.

06
DataSet & CommandBuilder

DataSet: In-memory representation of a relational database. Works offline.

CommandBuilder: Auto-generates INSERT, UPDATE, DELETE commands for a DataAdapter.

Connected vs Disconnected Data Model

FeatureConnected ModelDisconnected Model
ConnectionRemains open while workingCan be closed after data is retrieved
Main ObjectDataReaderDataSet with DataAdapter
Data AccessGenerally reads one row at a timeStores data in memory
SpeedFast for sequential readingSuitable for offline/in-memory work
Network UsageConnection remains activeConnection is opened only when required
ExampleReading student recordsLoading student records into a DataSet
Conclusion ADO.NET provides both models. DataReader is used for fast, sequential access while keeping the connection open, whereas DataAdapter and DataSet allow data manipulation in memory after the connection is closed.
02
5 Marks Question

Explain Query String and URL Encoding with Examples. State Advantages and Limitations.

Query String

A Query String is data appended to a URL after the ? (query delimiter). It is used to pass information between pages through the URL. Multiple parameters are separated using &.

https://iqra.ac.in/Profile.aspx?id=5&name=Riya

In ASP.NET, the values can be retrieved using the Request.QueryString collection:

string id = Request.QueryString["id"];
string name = Request.QueryString["name"];

// Passing Query String
Response.Redirect("Profile.aspx?id=" + txtID.Text + "&name=" + txtName.Text);

URL Encoding

Used to encode special characters in data so they can be safely transmitted through a URL. ASP.NET provides Server.UrlEncode().

Response.Redirect("Profile.aspx?id=" + txtID.Text + 
                  "&name=" + Server.UrlEncode(txtName.Text));

If txtName = Riya Sharma, the URL becomes ...name=Riya%20Sharma.

Advantages & Limitations

Advantages
  • 1 Simple to use.
  • 2 Useful for page-to-page communication.
  • 3 Easy to retrieve.
  • 4 Bookmarkable.
Limitations
  • 1 Visible to the user in address bar.
  • 2 Not suitable for sensitive data.
  • 3 Limited size (~2000 chars).
  • 4 Special characters require encoding.
In short Query String passes data through the URL, while URL Encoding makes it safe. Simple, but unsuitable for sensitive or large data.
03
5 Marks Question

Explain Session State Management with Example. Differentiate Session, Application and Cookies.

Session State is a server-side state management technique used to store user-specific data on the server and maintain it between different pages during a user's visit. Since HTTP is stateless, Session helps ASP.NET remember information between requests.

Each user gets a unique Session ID, and the default Session timeout is 20 minutes of inactivity.

Example

// Storing a value
Session["UserName"] = txtName.Text;

// Retrieving
if (Session["UserName"] != null) {
    lblUser.Text = Session["UserName"].ToString();
}

// Removing
Session.Remove("UserName");   // Remove one value
Session.Clear();              // Clear all values
Session.Abandon();            // End the session

Session Modes

InProc
Default; stores Session in IIS process memory.
StateServer
Stores Session in a separate ASP.NET State Service.
SQLServer
Stores Session in SQL Server.
Custom
Developer implements a custom storage provider.

Difference between Session, Application and Cookies

FeatureSessionApplicationCookies
StorageServerServerClient browser
ScopePer userAll usersPer user
PurposeUser-specific dataApplication-wide dataSmall user information
TimeoutDefault ~20 minutesApplication lifetimeConfigurable
SizeCan store .NET objectsCan store application dataAbout 4 KB
SecuritySuitable for sensitive dataSuitable for shared server dataNot suitable for sensitive data
In short Session → Server-side, one user
Application → Server-side, all users
Cookie → Client-side, one user
04
5 Marks Question

Explain ASP.NET State Management Techniques.

State Management is the technique of maintaining data between different requests and pages in an ASP.NET application. This is necessary because HTTP is stateless.

1. Client-Side State Management

Data is maintained on the client/browser.

ViewState
Stores control values in a hidden field during postbacks. Enabled by default.
Cookies
Small pieces of data stored in the user's browser (up to ~4 KB).
Hidden Fields
Stores data in an HTML hidden input field. Useful for small hidden data.
Query String
Passes data through the URL. Visible, not for sensitive info.

2. Server-Side State Management

Data is maintained on the web server.

Session State
Stores data for an individual user on the server (e.g., login info, cart).
Application State
Stores data shared by all users (e.g., total visit count). Available application lifetime.
Cache
Temporary server-side storage used for high-performance data access.

Comparison

TechniqueStorageScopeMain Use
ViewStateClient (hidden field)Current pageMaintain control values
CookiesClient browserPer userSmall user information
Query StringURLPer requestPass parameters between pages
SessionServerPer userLogin, cart, preferences
ApplicationServerAll usersApplication-wide data
05
5 Marks Question

Explain Web Services, Features, and Advantages. Describe SOAP and WSDL.

A Web Service is a software component accessible over a network that allows different applications to communicate and exchange information using standard protocols. In classic ASP.NET, they use the .asmx extension and expose methods via the [WebMethod] attribute.

Diagram Note: Draw the Web Service Communication Flow diagram from Page 7–8 of your Unit 4 notes illustrating a Web Service accessed by a website, mobile app and desktop app.

Features and Advantages

  • 01Platform Independent: Applications on different platforms can communicate.
  • 02Language Independent: Client and Service can be in different languages.
  • 03Interoperability: Uses standard technologies like HTTP, XML, SOAP.
  • 04Reusable: Single service used by multiple applications.
  • 05Loosely Coupled: Client only needs to know the service operation/parameters, not internal implementations.

SOAP and WSDL

SOAPWSDL
Simple Object Access ProtocolWeb Services Description Language
Used for message communication.Used to describe the Web Service.
Defines request/response message format.Describes operations, parameters and return values.
XML-based messaging protocol.XML-based service description document.
How messages are exchanged.What the service provides.
SOAP Structure: Consists of an Envelope (required), Header (optional), and Body (required). Draw diagram from Page 8.
Conclusion ASP.NET Web Services provide standard communication. SOAP defines how messages are exchanged, while WSDL describes what the service provides and how to communicate.
06
5 Marks Question

Explain the Steps to Create and Consume an ASMX Web Service.

An ASMX Web Service is a classic ASP.NET Web Service that uses the .asmx extension.

A. Steps to Create an ASMX Web Service

  • Step 1 Create a new ASP.NET Web Application (.NET Framework).
  • Step 2 Add New Item → Select Web Service (ASMX) (e.g., StudentService.asmx).
  • Step 3 Write the Web Service code in the .cs file using the [WebMethod] attribute.
  • Step 4 Run and Test the service in the browser.
[WebMethod]
public int Add(int a, int b)
{
    return a + b;
}

B. Steps to Consume the ASMX Web Service

Consuming means using the Web Service from a client application.

  • Step 1 Obtain the Web Service URL.
  • Step 2 In the client app, add a Web Reference / Service Reference using the URL.
  • Step 3 A Proxy Class is automatically generated from the WSDL.
  • Step 4 Create a Proxy Object and call the Web Service Method.
StudentWS.StudentService svc = new StudentWS.StudentService();
int result = svc.Add(10, 20);
lblResult.Text = result.ToString();

C. Overall Communication Flow

Create ASMX Service
        ↓
Write [WebMethod]
        ↓
Run & Test Service
        ↓
Get WSDL
        ↓
Add Web Reference
        ↓
Proxy Class Generated
        ↓
Client Calls Method
        ↓
SOAP Request
        ↓
Web Service Executes
        ↓
SOAP Response
        ↓
Client Receives Result
Diagram Note: Draw the Communication Flow diagram from Page 10 of your Unit 4 notes showing the exact sequence.