0% found this document useful (0 votes)
28 views94 pages

ASP.net

The document discusses various topics related to ASP.NET including what ASP.NET is, its features, literal controls, the page lifecycle and relevant events, .NET framework principles and design, Git, ADO.NET concepts like datasets and data access, caching, state management, web services, XML, and assemblies.

Uploaded by

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

ASP.net

The document discusses various topics related to ASP.NET including what ASP.NET is, its features, literal controls, the page lifecycle and relevant events, .NET framework principles and design, Git, ADO.NET concepts like datasets and data access, caching, state management, web services, XML, and assemblies.

Uploaded by

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

BCA-601-ASP.

Net using C
1. What is asp.net? What are advance features of asp.net?
2. What do you mean by literal control? Explain how it is useful in table
server control with example.
3. Explain the life cycle of a web page with relevant events. 4. Explain the
principal and design of .Net frame work.
5. What is GIT? Also define its types.
6. What is data set data table and data view in ADO.NET.
7. Explain about the data reader, data adapter and data Column and data
row in Ado .Net.
8. Describe the classes required in communicating OLED using ADO.NET
9. Explain difference between ADO and ADO.NET 10. Differentiate between
Absolute expiration and sliding expiration
11. Define Caching and its types.
12. Explain Reverse Proxy?
13. Define the client dedicated server.
14. Define the Page Fragment Caching.
15. Explain Client side state management
16. What is Data Hiding? Explain Classes and Objects required in Data
Hiding in ASP.NET
17. Explain Server side state management
18. Explain about the view state and hidden field in Client state
management.
19. Define the Application state and Session state in Server state
management.
20. Explain UDDI.
21. Explain the Database access in ASP.NET. Describe Data Source
Control.
22. What is a web service? Explain HTTP Request, HTTP Response and
methods for submitting information in HTTP Request.
23. Explain ADO.NET Object Model.
24. Explain the role of Simple Object Access Protocol in web services. 25.
What is SOAP (Simple Object Access protocol.) in web services? 26.
Describe the xml elements and naming rules in xml.
27. What is XML? Describe characteristics and uses of XML. How it is
different from HTML
28. Explain Data Caching with example
29. What is a .Net Assembly? Explain different kind of Assemblies
1. What is asp.net? What are advance features of asp.net?

ASP.NET is a web development platform, which provides a programming model, a


comprehensive software infrastructure and various services required to build up
robust web applications for PC, as well as mobile devices.

ASP.NET works on top of the HTTP protocol, and uses the HTTP commands and
policies to set a browser-to-server bilateral communication and cooperation.

ASP.NET is a part of Microsoft .Net platform. ASP.NET applications are compiled


codes, written using the extensible and reusable components or objects present
in .Net framework. These codes can use the entire hierarchy of classes in .Net
framework.

The ASP.NET application codes can be written in any of the following languages:

 C#

 Visual Basic.Net

 Jscript

 J#

ASP.NET is used to produce interactive, data-driven web applications over the


internet. It consists of a large number of controls such as text boxes, buttons, and
labels for assembling, configuring, and manipulating code to create HTML pages.

ASP.NET Features

ASP.NET is full of features and provides an awesome platform to create and


develop web application

o Server Controls

o Master Pages

o Working with data


o Membership

o Client Script and Client Frameworks

o Routing

o State Management

o Security

o Performance

o Error Handling

Server Controls

Web Forms provides rich set of server controls. These controls are objects that run
when the page is requested and render markup to the browser. Some Web server
controls are similar to familiar HTML elements, such as buttons and text boxes. It
also provides controls that we can use to connect to data sources and display data.

Master Pages

It allowsus to create a consistent layout for the pages in our application. This page
defines the look and feel and standard behavior that we want for all of the pages in
our application. When users request the content pages, they merge with the master
page to produce output that combines the layout of the master page with the content
from the content page.

Working with Data

In an ASP.NET Web Forms application, we use data-bound controls to automate the


presentation or input of data in web page UI elements such as tables and text boxes
and drop-down lists.

Membership
Project's Account folder contains the files that implement the various parts of
membership: registering, logging in, changing a password, and authorizing access.
Additionally, ASP.NET Web Forms supports OAuth and OpenID. These
authentication enhancements allow users to log into your site using existing
credentials, from such accounts as Facebook, Twitter and Google.

Client Script and Client Frameworks

We can enhance the server-based features of ASP.NET by including client-script


functionality in ASP.NET Web Form pages. We can use client script to provide a
richer, more responsive user interface to the users. We can also use client script to
make asynchronous calls to the Web server while a page is running in the browser.

Routing

We can configure URL routing of our application. A request URL is simply the URL a
user enters into their browser to find a page on our web site. We use routing to
define URLs that are semantically meaningful to users and that can help with
search-engine optimization (SEO).

State Management

ASP.NET Web Forms includes several options that help you preserve data on both
a per-page basis and an application-wide basis.

Security

Developing a secure application is most important aspect of software development


process. ASP.NET Web Forms allow us to add extensibility points and configuration
options that enable us to customize various security behaviors in the application.

Performance

Web Forms provides good performance and allows us to modify performance


related to page and server control processing, state management, data access,
application configuration and loading, and efficient coding practices.
2. What do you mean by literal control? Explain how it is useful in table server
control with example.

Use the System.Web.UI.WebControls.Literal control to reserve a location on the


Web page to display text. The Literal control is similar to the Label control, except
the Literal control does not allow you to apply a style to the displayed text. You can
programmatically control the text displayed in the control by setting
the Text property.

 The Literal Control is similar to the Label Control as they both are used to display
static text on a web page.

 The Literal Control is not inherited from WebControl namespace.

 The Literal Control doesn't provide substantial functionality but Literal text is
programmable.

 It doesn't add any HTML elements to the web page. This control makes it
possible to add HTML code directly in the code designer window without
switching to design view and clicking the HTML button to edit the HTML.

 You cannot apply a style to a literal control.

 Unlike Label control, there is no property like BackColor, ForeColor, BorderColor,


BorderStyle, BorderWidth, Height etc. for Literal control. That makes it more
powerful, you can even put a pure HTML contents into it.

 Literal control is one of the rarely used controls but it is very useful.
 Literal control is light weight control.
 The Literal Control is useful when you want to add text to the output of the page
dynamically (from the server).
 With that you can even programmatically manipulate the Literal text from the
code behind.

How to code Literal control in .aspx page


1. <asp:Literal ID="LiteralText" runat="server" Text="This is example of Literal"></
asp:Literal>

The above code will be rendered as:

1. <div>

2. This is example of Literal

3. </div>

Output of above code

Table showing mode property of the Literal control:

Mode Description

PassThroug The contents of the control are not modified.


h

Encode The contents of the control are converted to an HTML-encoded string.

Unsupported markup-language elements are removed from the


Transform
contents of the control. If the Literal control is rendered on a browser
that supports HTML or XHTML, the control's contents are not
modified.
3.Explain the life cycle of a web page with relevant events

When an ASP.NET page runs, the page goes through a life cycle in which it performs a
series of processing steps. These include initialization, instantiating controls, restoring
and maintaining state, running event handler code, and rendering. It is important for you
to understand the page life cycle so that you can write code at the appropriate life-cycle
stage for the effect you intend.

If you develop custom controls, you must be familiar with the page life cycle in order to
correctly initialize controls, populate control properties with view-state data, and run
control behavior code. The life cycle of a control is based on the page life cycle, and the
page raises many of the events that you need to handle in a custom control.

Page Lifecycle stages

The following table contains the lifecycle stages of ASP.NET web page.

Stage Description

Page request This stage occurs before the lifecycle begins. When a page is requested by
the user, ASP.NET parses and compiles that page.

Start In this stage, page properties such as Request and response are set. It also
determines the Request type.

Initialization In this stage, each control's UniqueID property is set. Master page is applied
to the page.

Load During this phase, if page request is postback, control properties are loaded
with information.
Postback In this stage, event handler is called if page request is postback. After that,
event handling the Validate method of all validator controls is called.

Rendering Before rendering, view state is saved for the page and all controls. During
the rendering stage, the page calls the Render method for each control,
providing a text writer that writes its output to the OutputStream object of the
page's Response property.

Unload At this stage the requested page has been fully rendered and is ready to
terminate.at this stage all properties are unloaded and cleanup is performed.

A requested page first loaded into the server memory after that processes and sent to
the bowser. At last it is unloaded from the server memory. ASP.NET provides methods
and events at each stage of the page lifecycle that we can use in our application. In the
following table, we are tabled events.

ASP.NET Life Cycle Events

Page Event Typical Use

PreInit This event is raised after the start stage is complete and before the
initialization stage.

Init This event occurs after all controls have been initialized.
We can use this event to read or initialize control properties.

InitComplete This event occurs at the end of the page's initialization stage.
We can use this event to make changes to view state that we want to
make sure are persisted after the next postback.

PreLoad This event is occurs before the post back data is loaded in the controls.

Load This event is raised for the page first time and then recursively for all
child controls.
Control events This event is used to handle specific control events such as Button
control' Click event.

LoadComplete This event occurs at the end of the event-handling stage.


We can use this event for tasks that require all other controls on the
page be loaded.

PreRender This event occurs after the page object has created all controls that are
required in order to render the page.

PreRenderComplet This event occurs after each data bound control whose DataSourceID
e property is set calls its DataBind method.

SaveStateComplete It is raised after view state and control state have been saved for the
page and for all controls.

Render This is not an event; instead, at this stage of processing, the Page
object calls this method on each control.

Unload This event raised for each control and then for the page.
4. Explain the principal and design of .Net frame work

.Net Framework is a software development framework created by Microsoft to


develop and run windows applications. .Net framework is an element of the .Net
programming language. It is a collection of technologies to build apps for different
platforms like Windows, Linux, ios, Android, etc.

.NET Framework can be hosted by unmanaged components that load the common
language runtime into their processes and initiate the execution of managed code,
thereby creating a software environment that exploits both managed and
unmanaged features. .NET Framework not only provides several runtime hosts but
also supports the development of third-party runtime hosts.

The .NET Framework class library is a collection of reusable types that tightly
integrate with the common language runtime. The class library is object oriented,
providing types from which your own managed code derives functionality. This not
only makes the .NET Framework types easy to use but also reduces the time
associated with learning new features of the .NET Framework. In addition, third-
party components integrate seamlessly with classes in the .NET Framework.

For example, the .NET Framework collection classes implement a set of interfaces
for developing your own collection classes. Your collection classes blend seamlessly
with the classes in the .NET Framework.

Interoperability

Because interaction between new and older applications is commonly required,


the .NET Framework provides means to access functionality that is implemented in
programs that execute outside the .NET environment. Access to COM components
is provided in the System.Runtime.InteropServices and System.EnterpriseServices
namespaces of the framework
Common Runtime Engine

The Common Language Runtime (CLR) is the virtual machine component of


the .NET Framework. All .NET programs execute under the supervision of the CLR,
guaranteeing certain properties and behaviors in the areas of memory management,
security, and exception handling.

Language Independence

The .NET Framework introduces a Common Type System, or CTS. The CTS
specification defines all possible datatypes and programming constructs supported
by the CLR and how they may or may not interact with each other conforming to the
Common Language Infrastructure (CLI) specification. Because of this feature,
the .NET Framework supports the exchange of types and object instances between
libraries and applications written using any conforming .NET language.

Simplified Deployment

The .NET Framework includes design features and tools that help manage the
installation of computer software to ensure that it does not interfere with previously
installed software, and that it conforms to security requirements.

Security

The design is meant to address some of the vulnerabilities, such as buffer overflows,
that have been exploited by malicious software. Additionally, .NET provides a
common security model for all applications.

Portability

The design of the .NET Framework allows it to theoretically be platform agnostic,


and thus cross-platform compatible. That is, a program written to use the framework
should run without change on any type of system for which the framework is
implemented.
5. What is GIT? Also define its types.

A JIT or Just-In-Time compiler is a foundational component for running the .NET


applications. It functions on the basis of dynamic code translations, leading to
optimizing the code during the runtime. JIT is also compatible with compiling a
specific method, class, or function, helping to enhance the application speed and
performance.
The primary purpose of using the JIT compiler is its capability to compile
all .NET-supported programming languages. Whether you develop .NET
software using C#, Visual Basic, or F#, it can compile them all and run on a
specific platform.
In addition, JIT gets its leverage of multi-language compilation from CLR
(Common Language Runtime). The CLR converts the programming language
code into an intermediate language, understandable by the .NET compilation
program. Further, the JIT takes that intermediate language as input and converts
it to the machine language.
In the .NET ecosystem, you can find the following three primary JIT compilers.
 The Pre-JIT Compiler
 The Normal JIT Compiler
 The Econo JIT Compiler

The Pre-JIT Compiler


The Pre-JIT compiler type is popular among dotnet developers. The pre-JIT compiler
can potentially convert the whole source to native code in one cycle. With the help of
NGen, it creates a native image of the application that can be run on a single platform.

For better understanding, suppose you have a cross-platform compatible .NET


application able to run on Windows, Linux, and macOS. When you use a pre-JIT
compiler on its source code, you will get a platform-specific app file. Thus, now
your .NET application will run on only one of the mentioned operating systems.
Furthermore, pre-JIT provides an advantage over other JIT compiler types. It eliminates
the initial compilation delay, boosting the .NET application loading speed and
performance. You get the benefit of the warm startup, which means that assembly data
remains available in the cache memory for faster access and execution. As a result, the
disk doesn’t have to look into the disk drive, saving the overall time.

The Normal JIT Compiler


The normal JIT compiler works at runtime and executes only those methods that are
called at a specific time. For instance, suppose you have a program with different
methods for addition, subtraction, multiplication, and division. If you call the addition
method, the normal JIT compiler will only compile that specific method. Other methods
will remain uncompiled.

Further, the compiled method will be stored in the memory and called “jitted.” Also,
when that compiled method will be called in the future, it will not require JIT compilation.
The application will directly access and utilize the compiled method from cache
memory.

The Econo JIT Compiler


The working of the Econo JIT compiler is similar to the normal JIT compiler. It also
compiles only the methods called during the runtime. But, it doesn’t save them in the
memory. Due to it, the application performance gets more optimized as compared to
speed while using a normal JIT compiler.

Nowadays, Econo JIT is not used and not even available for .NET development. Its
usage was stopped when Microsoft eliminated the support for .NET 2.0. Therefore, you
should only know about this compiler for clarification about types of JIT compilers
in .NET.

The Working of JIT Compiler

The working of the JIT compiler is quite streamlined. However, before you learn the JIT
works, you must know that there’s another compiler present that provides the input to
the JIT compiler. To understand it easily and instantly, you should undergo the following
steps.

 Step 1: The application’s source code written in C#, F#, and Visual Basic gets
passed to the traditional compiler.
 Step 2: The traditional compiler uses the source code as input and starts
converting it to MSIL or MS intermediate language.
 Step 3: The converted source code (intermediate language code) gets passed to
the JIT compiler. It assesses the behavior and other code characteristics.
 Step 4: The JIT compiler starts its functions by applying dead code elimination,
loop unrolling, and inlining. All these techniques are used to optimize code for the
runtime.
 Step 5: JIT initiates the compilation and translates the intermediate language
code to machine language, i.e., 0s and 1s.
6. What is data set data table and data view in ADO.NET

ADO.NET provides components to view data in data bound controls. These


components are easy to use and provide rapid development. You just drag and drop
these controls to a form, set their properties, and bind them to Data- bound controls.
Then you're all set to run your programs. The DataView and DataViewManager classes
fall in this category. You can use these classes to represent different views of a data
table based on different filter and sort criterion. You can use these classes either at
design-time or run-time modes. Earlier, you've seen how use these class either at
design-time modes. You've also seen how to use class objects at design-time. In this
article, you'll see how to use these classes programmatically.

A DataSet is a key component in the ADO.NET data model. It's an in-memory


representation of one or multiple data tables, relations, and constraints. It provides a
communication between the actual data Windows forms and Web Forms controls to
provide the data a view through the DataView and the DataViewManager. Not only this,
but a DataSet offers much more than that.

The DataView is useful when you need to bind a DataTable or multiple DataTable
objects with data-bound controls. You can also represent multiple views of same data
by applying a filter and sort on a data table, and you can bind these multiple views to
different data-bound controls such as a DataGrid, DataList, comboBox, and ListBox
control.
The DataSet

A DataSet object plays a vital role in the ADO.NET component model. A DataSet
represents disconnected cache of Data in the form of tables, rows, columns, or XML
schemas. If you've ever programmed a database application in previous versions of
Visual studio, you're probably familiar with recordset. A recordset object was a way to
represent data in your programs. Similar to a recordset, a DataSet represent data in
your applications. Once you have constructed a DataSet, you can get or set data in your
Applications or your data source. As mentioned earlier, the DataSet works in both
connected and disconnected environment. A DataSet communicates with a
DataAdapter and calls DataAdapter's Fill method to fill data from a DataAdapters. You
can fill a DataSet object with multiple tables or stored from a DataAdapter. In this article,
you'll see how it works with DataTable and DataView objects.

DataTable

The rows of a DataTable represent individual records or data entries, while the columns
represent the various attributes or fields associated with the data. Together, the rows
and columns form a tabular structure to store and manage data within the DataTable.

In certain scenarios, we may need to determine the number of tables present within a
DataSet. To accomplish this, we can access the DataTableCollection property of the
DataSet. This collection provides access to the DataTable objects contained within the
DataSet, allowing us to query the count or utilize other appropriate methods to retrieve
the number of tables present.

DataGridView control

The DataGridView control simplifies the process of defining the visual aspects of cells
and formatting the display of cell values. Cells serve as the fundamental units of
interaction within the DataGridView, all deriving from the base class DataGridViewCell.
Each cell within the control can possess its own unique style, encompassing elements
such as text format, background color, foreground color, and font. Nevertheless, it is
common for multiple cells to share certain style characteristics. By default, the data type
for the cell's Value property is Object.
7. Explain about the data reader, data adapter and data Column and data row
in Ado .Net.

DataReader

DataReader is used to read the data from the database and it is a read and forward only
connection oriented architecture during fetch the data from database. DataReader will
fetch the data very fast when compared with dataset. Generally, we will use
ExecuteReader object to bind data to datareader.

DataSet

DataSet is a disconnected orient architecture that means there is no need of active


connections during work with datasets and it is a collection of DataTables and relations
between tables. It is used to hold multiple tables with data. You can select data form
tables, create views based on table and ask child rows over relations. Also DataSet
provides you with rich features like saving data as XML and loading XML data.

DataAdapter

DataAdapter will acts as a Bridge between DataSet and database. This dataadapter
object is used to read the data from database and bind that data to dataset.
Dataadapter is a disconnected oriented architecture.

DataTable

DataTable represents a single table in the database. It has rows and columns. There is
no much difference between dataset and datatable, dataset is simply the collection of
datatables.
8. Describe the classes required in communicating OLED using ADO.NET

There are a number of ways to construct a command object. You can pass the
command a SQL query string. You can pass it a string and a connection, or you can
pass it a string, a connection, and a transaction. The following code shows you three
different ways to create a command object. This code constructs a connection and SQL
string:

// connection and SQL strings


string ConnectionString = @" provider=Micosoft.Jet.OLEDB.4.0;" + "Data
source= c:\\ Northwind.mdb";
string SQL = "SELECT OrderID, CustomerID FROM Orders";

Now create OleDbCommand object using a constructor with no arguments. Later you
set OleDbCommand's Connection and CommandText properties to connect to a
connection and set SQL statement, which this command will be executing:

OleDbCommand cmd = new OleDbCommand();


cmd.Connection = conn;
cmd.CommandText = SQL;

In the second form, you create an OleDbCommand object by directly passing a SQL
query and the OleDbConnection object as the first and second arguments:

// Create command object


OleDb command cmd = new OleDbCommand (SQL, conn);

The third way is to create a command by just passing a SQL query as the argument and
setting its Connection property later:
// Create command object
OleDbCommand cmd = new OleDbCommand(SQL);
cmd.Connection = conn;

Listing 5-30 shows you how to connect to the North Wind Access 2000 database, read
all the records from the Order table, and display the first and second column data to the
console output. The new things you'll notice in this code are ExcuteReader and
OleDbDataReader. An OleDbDataReader is data reader class, and ExecuteReader fills
data from a data source to the data reader based on the SQL query.

Listing 5-30. Using OleDbCommand to read data from database

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Connection and SQL strings
string ConnectionString = @"Provider= Microsoft.Jet.OLEDB. 4.0;" + "Data
Source =c:/nothwind.mdb";
string SQL = "SELECT * FROM Orders";

//Create connection object


OleDbConnection conn = new OleDbConnection(ConnectionString);
// create command object
OleDbCommand cmd = new OleDbCommand(SQL);
cmd.Connection = conn;

// open connection
conn.Open();

// Call command's ExcuteReader


OleDbDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
Console.Write("OrderID :" + reader.GetInt32(0).ToString());
Console.Write(" ,");
Console.WriteLine("Customer: " + reader.GetString(1).ToString());
}

// close reader and connection


reader.Close();
conn.Close();
}
}
}

The output listing 5-30 looks like figure 5-30.


9. Explain difference between ADO and ADO.NET

ADO:

ADO stands for ActiveX Data Objects. In this the programmers use a generic set of
objects, no matter the underlying data sources. It requires locking of database
resources and a lengthy connections for applications. In ADO connection is creating by
using a single Connection object.

ADO.NET:

ADO.NET is an advance version of ADO. It interacts with databases and have a


consistent access to various data sources. It does not requires locking and a lengthy
connections for its applications. ADO.NET can have a separate objects that represent
connections to different data sources which make access faster and more efficient.

It uses a multilayered architecture that includes a few concepts such as Connection,


Command, and DataSet objects. ADO.NET is truly the data access technology for
current and future applcations.

Head to Head ADO ADO.NET


differences

1 Data In ADO, data is represented In ADO.NET, data is represented by a


Representation by a RecordSet object, DataSet object, which can hold data from
which can hold data from various data sources, integrate it, and
one data source at a time. after combining all the data it can write it
back to one or several data sources.

2 Data Reads In ADO, data is read in In ADO.NET, data is read either in a


sequential manner. sequential or non-sequential manner.

3 Disconnected ADO first makes a call to an It uses standardized calls such as


Access OLE DB provider. It DataSetCommand object to
supports the connected communicate with a database and with
access, represented by the the OLE DB provider.
Connection with a
database.

4 Creating Cursors It allows us to create client- ADO.NET either created client-side or


side cursor only. server-side cursors.

5 Locking ADO has the feature of This features is not used in ADO.NET.
locking.&

6 XML integration This feature is not used in This feature is used in ADO.NET.
ADO.

7 Relationship It requires SQL Join and It uses DataRelation objects for


between Multiple UNIONs to combine data combining data from multiple tables
Tables from multiple tables in a without the use of SQL Join and
single RecordSet. UNIONs.

8 Conversion ADO requires data to be ADO.NET does not require complex


converted to data types conversions that wasted processor time.
supported by receiving
system.

9 Data Storage In ADO data is stored in a In ADO.NET, data is stored in XML form.
binary form. With the use of XML, it stores data more
easily.

10 Firewalls In ADO, firewalls are In ADO.NET firewalls are supported


typically configured to because ADO.NET DataSet objects use
prevent system-level XML for representing data.
requests, such as COM
marshaling.

11 Communication In this, objects are It uses XML for communication.


communicate in a binary
mode.

12 It uses a Connection object ADO.NET does not require data


Programmability to transfer commands to a constructs because it uses strongly
data source with defined typed characteristics of XML.
data constructs.

13 Connection ADO supports only one ADO.NET supports two models of


Model model of connection i.e. connection i.e. Connection-Oriented
Connection Oriented Data Data Access Architecture and
Access Architecture Model. Disconnected Oriented Data Access
Architecture.

14. Environment ADO was geared for a two- ADO.NET address a multi-tiered
tiered architecture. architecture.

15. Metadata It derives information In ADO.NET derives information at


automatically at runtime design time on metadata in order to
based on metadata. provide better runtime performance.

16. Multiple In ADO multiple In ADO.NET multiple transactions can be


Transactions transactions cannot be send using a single connection.
send using a single
connection.

17. Data Types It has a less number of data It has a huge and rich collection of data
types. types.

18. Serialization ADO serialized data in a ADO.NET serialized data using XML.
proprietary protocol.

19. Security ADO is less secured. ADO.NET much secured as compared to


ADO.
20 Based on ADO is based on ADO.NET is a Common Language
Component Object Runtime based library.
Modelling.

21 Scalability ADO technology have less ADO.NET have more scalability with the
scalable. use of locking mechanism.

22. Resources ADO technology use more ADO.NET conserves limited resources.
resources as compared to
ADO.NET.

23. Performance ADO have a poor In ADO.NET performance is much better


performance. as compared to ADO.
10. Differentiate between Absolute expiration and sliding expiration

ASP.net cache is great feature through which we can increase the performance of the
our web application via reducing server round trips to database. We can cache any
serializable data into the cache. There are so many ways to cache data but one of the
simplest way to cache data like insert data into cache object. Here we must need to
validate cache if any data is changed and there are so many ways from where we can
set dependency to validate the cache like files,SQL Cache Dependency etc. We also
can validate cache or expire via setting time to duration to its object. Like after the
defined time our cache will expire and then it will again put new fresh data into the
cache. This is called as time base expiration. We can put this kind of expiration via two
way.

1. Absolute Expiration

2. Sliding Expiration

Absolute Expiration: Absolute expiration means It will expire cache after some time
period set at the time of activating cache. This will be absolute expiration whether cache
will be used or not It will expire the cache. This type of expiration used to cache data
which are not frequently changing.

Sliding Expiration: Sliding expiration means It will expire cache after time period at the
time of activating cache if any request is not made during this time period. This type of
expiration is useful when there are so many data to cache. So It will put those items in
the cache which are frequently used in the application. So it will not going to use
unnecessary memory.

Here is the example how we can set the sliding expiration and absolute expiration.

1 string cacheData = "The data to be cached";


//Absolute Expiration
2
Cache.Insert("AbsoluteCacheKey", cacheData, null,
3
DateTime.Now.AddMinutes(1),
4
System.Web.Caching.Cache.NoSlidingExpiration);
5
//Sliding Expiration
6
Cache.Insert("SlidingExpiration", cacheData, null,
7
System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(1));

In above example I have created the a string to be cache that can be any serialized
data. In the absolute expiration you can see that it will expires after one minute whether
its accessed or not. While in sliding expiration it will expire cache if cache is not
accessed within specified time.
11. Define Caching and its types.

Caching is a technique of storing frequently used data/information in memory, so that,


when the same data/information is needed next time, it could be directly retrieved from
the memory instead of being generated by the application.

Caching is extremely important for performance boosting in ASP.NET, as the pages and
controls are dynamically generated here. It is especially important for data related
transactions, as these are expensive in terms of response time.

Caching places frequently used data in quickly accessed media such as the random
access memory of the computer. The ASP.NET runtime includes a key-value map of
CLR objects called cache. This resides with the application and is available via the
HttpContext and System.Web.UI.Page.

In some respect, caching is similar to storing the state objects. However, the storing
information in state objects is deterministic, i.e., you can count on the data being stored
there, and caching of data is nondeterministic.

The data will not be available in the following cases:

 If its lifetime expires,


 If the application releases its memory,
 If caching does not take place for some reason.

You can access items in the cache using an indexer and may control the lifetime of
objects in the cache and set up links between the cached objects and their physical
sources.

Caching in ASP.Net

ASP.NET provides the following different types of caching:


 Output Caching : Output cache stores a copy of the finally rendered HTML
pages or part of pages sent to the client. When the next client requests for this
page, instead of regenerating the page, a cached copy of the page is sent, thus
saving time.
 Data Caching : Data caching means caching data from a data source. As long
as the cache is not expired, a request for the data will be fulfilled from the cache.
When the cache is expired, fresh data is obtained by the data source and the
cache is refilled.
 Object Caching : Object caching is caching the objects on a page, such as data-
bound controls. The cached data is stored in server memory.
 Class Caching : Web pages or web services are compiled into a page class in
the assembly, when run for the first time. Then the assembly is cached in the
server. Next time when a request is made for the page or service, the cached
assembly is referred to. When the source code is changed, the CLR recompiles
the assembly.
 Configuration Caching : Application wide configuration information is stored in
a configuration file. Configuration caching stores the configuration information in
the server memory.

In this tutorial, we will consider output caching, data caching, and object caching.

Output Caching

Rendering a page may involve some complex processes such as, database access,
rendering complex controls etc. Output caching allows bypassing the round trips to
server by caching data in memory. Even the whole page could be cached.

The OutputCache directive is responsible of output caching. It enables output caching


and provides certain control over its behaviour.

Syntax for OutputCache directive:

<%@ OutputCache Duration="15" VaryByParam="None" %>


Put this directive under the page directive. This tells the environment to cache the page
for 15 seconds. The following event handler for page load would help in testing that the
page was really cached.

protected void Page_Load(object sender, EventArgs e)


{
Thread.Sleep(10000);
Response.Write("This page was generated and cache at:" +
DateTime.Now.ToString());
}

The Thread.Sleep() method stops the process thread for the specified time. In this
example, the thread is stopped for 10 seconds, so when the page is loaded for first
time, it takes 10 seconds. However, next time you refresh the page it does not take any
time, as the page is retrieved from the cache without being loaded.

The OutputCache directive has the following attributes, which helps in controlling the
behaviour of the output cache:

Attribute Values Description

Specifies that output could


DiskCacheable true/false be written to a disk based
cache.

Specifies that the "no


NoStore true/false store" cache control
header is sent or not.

Name of a cache profile as


CacheProfile String name
to be stored in web.config.

VaryByParam None Semicolon delimited list of


* string specifies query string
values in a GET request or
Param- name variable in a POST
request.

Semicolon delimited list of


* strings specifies headers
VaryByHeader
Header names that might be submitted by
a client.

Tells ASP.NET to vary the


Browser output cache by browser
VaryByCustom
Custom string name and version or by a
custom string.

Any: page may be cached


anywhere.
Client: cached content
Any remains at browser.
Client Downstream: cached
Location Downstream content stored in
Server downstream and server
None both.
Server: cached content
saved only on server.
None: disables caching.

Number of seconds the


Duration Number
page or control is cached.
12. Explain Reverse Proxy?

Using a Reverse Proxy

Among the various elements of a network infrastructure (such as DNS servers, firewalls,
proxies and similar), reverse proxies gained a lot of popularity not only among IT people
but also among developers. This is mainly due to the growth in popularity of
microservice architectures and to advanced integration needs between technical
partners.

What is a Reverse Proxy

A standard proxy server acts as an intermediary between a client and a server in order
to perform processing like caching, traffic monitoring, resource access control, etc. The
relevant thing is that the client requests to contact a specific server and the proxy, after
evaluating how to satisfy this request, contacts the target server on behalf of the client.

A reverse proxy is a special type of proxy server that hides the target server to the
client. The client requests a resource to the proxy server which retrieves it from another
server and provides it to the client. In this case, the client has no idea that the resource
comes from another server.

Why Use a Reverse Proxy

A reverse proxy can be used in different contexts:

 Load balancing:

Maybe this is one of the most familiar uses of a reverse proxy. It can distribute the
requests load among a set of identical servers accordingly to some specific algorithm
providing support for scalability and availability of a system.

 URL rewriting:
Having meaningful URLs is crucial from an SEO standpoint. If you cannot change the
URLs of your website, you can hide them behind a reverse proxy that exposes to users
and web crawlers a more attractive version.

 Static content serving:

Many reverse proxy servers may be configured to act as web servers. This allows you
to use them for providing static content, such as HTML pages, JavaScript scripts,
images, and other files while forwarding requests for dynamic content to dedicated
servers. This is a sort of load balancing based on the content type.

 API gateway:

In a system with a microservice architecture, you have multiple servers offering different
services through their APIs. You can use a reverse proxy to expose a single entry point
for the combination of the server's APIs.

 Multiple website combining:

This is pretty similar to the API gateway context. In this case, you can have a single
entry point for multiple websites, possibly with a centralized homepage.

Why Implementing a Custom Reverse Proxy

One of the most popular reverse proxies is NGINX. Of course, you can use other tools
like Pound or Squid, or you can also configure the Apache Web server to act as a
reverse proxy. These tools offer a lot of configuration options that allow you to set up
your system in most common scenarios. Some of them also provide the ability to extend
their functionality with scripting languages, such as, for example, the Lua scripting
language in NGINX. This capability allows you to meet some processing needs that the
simple server configuration doesn't provide: HTTP header manipulation, conditional
request forwarding, simple content transformation, etc.

However, you may find scenarios where even an integrated scripting language is not
enough for your needs due to the complexity of the scenario itself or because the scripts
become hard to maintain. Consider, for example, a scenario where you need to expose
a remote Web application within the current domain and need to prepare the HTTP
requests by injecting data from a database and manipulate the responses to integrate
them in the current environment. Or a scenario where you need to apply complex
custom rules to analyze the HTTP traffic.

If you are in such a situation, you may need to build your own custom reverse proxy.

Implementing a Reverse Proxy in C#

Implementing the core of your own reverse proxy is not so hard as it may sound. Of
course, you will be unlikely to create a reverse proxy with all the options that NGINX or
other similar tools can provide. However, you can focus on your specific goal in order to
solve it at your best without resorting to complex configurations and scripts.
13. Define the client dedicated server.

A dedicated server is a powerful hosting solution offered by InMotion Hosting. It refers


to a physical server entirely dedicated to a single customer. Unlike shared hosting,
where multiple users share server resources, a dedicated server provides exclusive
control and resources to meet specific needs.

With a dedicated server, customers enjoy enhanced performance, scalability, and


security. They have complete administrative access, allowing them to customize the
server environment based on their requirements.

InMotion Hosting’s dedicated servers offer robust hardware, reliable network


connectivity, and round-the-clock technical support, ensuring optimal performance and
uninterrupted online presence for businesses and individuals with demanding
applications and website traffic.

A dedicated server is known as one of the highest-performance hosting options. We like


to think of a dedicated server like owning your own house. No one will bother you and
you can do whatever you’d like. Whereas a shared server is much like living in condo
where you have to share everything.

Dedicated servers allow for:

 24/7 uptime

 Faster connection speeds

 Less risk of virus attacks

 Maintenance on the fly


Dedicated servers aren’t specifically designed for one purpose. They can be used to
host websites, game servers, or anything that requires a place for multiple computers to
store and read files.

Anticipated Growth and Increased Traffic

If you have upgraded to a dedicated server you may have upgraded because of a
prediction of the growth of your business. This may include having increased traffic,
more products to display, or simply more functionality that you need to provide through
the server to your customers.

The dedicated server provides you the flexibility to adjust to increased traffic on your
website while also having a positive impact on your page loading times. This may come
at a premium cost, but you get more power for your money and more satisfied
customers.

Security and Control

One of the primary initial advantages that dedicated hosting offers is its ability to secure
your dedicated server. Particularly in regulated industries where upholding the privacy
of customer data and information is paramount, sharing a server with another company
is not a viable option. This is because it introduces the risk that these other entities
could potentially access the data and customer information stored on your server.

If you are on the same server with a spammer or malicious website meant to spread
viruses or other malware, this can open your website up to security issues. Your
website may even be shut down indefinitely if the authorities seize the server hardware
because of another malicious site on the same server. If your website handles credit
card transactions or other data that needs to be encrypted and closely guarded, you are
better off with a dedicated server.

Each server has a unique IP address. Therefore, if you’re on a dedicated server, your
website has its own IP address. But if you are on a shared server, your website will
share the IP address with the other sites hosted on the shared server. And if one of
those other sites is known to be a source of spam, your website’s Search Engine
Optimization (SEO) ranking may be negatively impacted because of its connection with
suspicious content. Your website may even be blocked from search engines.

As a means of maintaining server security, you will be able to install the highest level of
security available to you. Not only will your data be secured, but also your applications
and your customer database. One aspect that makes this so appealing for business
owners is that you will have total control over your site, without having to bend to the
needs of other businesses on your shared server or the configurations of your web
hosting service.

Managed Hosting

InMotion Hosting provides Managed Hosting services that you can take advantage of,
which help you set-up the server to your requirements and help with regular
maintenance and updates.

No Shared Resources

With a shared server, you are at the mercy of the limitations placed by having to share
resources. This means that the CPU processing power and RAM are all distributed (and
not evenly) with the other sites on the server.

If a website on the server is running bad scripts that eat up lots of memory, then it can
impact your website’s performance. The same is true if your server neighbors have a
spike in website traffic. This can eat up the bandwidth on the server and slow your
website down significantly. Additionally, shoppers may associate slow load times with
lower quality. If your website takes too long to load, consumers may seek out your
competitors’ sites instead.

With a dedicated server, however, you don’t have to share resources. The full capacity
of the server is at your disposal and you won’t have to worry about someone else
slowing down your site.

Increased Site Speed


With more resources available, elements can load faster. In addition to this, site speed
yields several other benefits.

Improved SEO: It is well-known that site speed is one of the ranking factors Google
uses to determine search engine ranking. Further, research has shown that they may
be using “time to first byte” as the official means of measurement. What does that
mean? In simple terms: a fast website will help you show up higher in Google search
results, while a slow website will likely make you show up lower.

Your bottom line: Site speed has a direct impact on conversion rate, revenue, and
user experience in the following ways:

 A slow site is less likely to get a lot of return traffic.

 Every additional second added onto your load time results in 7% fewer
conversions.

 A one-second delay in response time can result in 11% fewer page views and a
16% loss in customer satisfaction.

 46% of people who abandon their shopping cart cite slow website speed as the
reason.

 Greater customization options: Having an entire server’s worth of resources to


yourself means that you can likely add a lot of custom features (like video
streaming or MP3s) without impacting your site’s speed. And your highly
customized site will not only look great but will be memorable to visitors and
create a great user experience.

Customization Possibilities

With a shared server, you have a “one size fits all” mentality when it comes to server
configurations. But with a dedicated server, you can specifically configure your server to
work best with your website. This can include configuration for a Content Management
System (CMS) platform such as WordPress, Drupal, or Magento hosting for
eCommerce.
14. Define the Page Fragment Caching.

Fragment caching refers to the caching of individual user controls within a Web Form.
Each user control can have independent cache durations and implementations of how
the caching behavior is to be applied. Fragment caching is useful when you need to
cache only a subset of a page. Navigation bars, header, and footers are good
candidates for fragment caching.

Fragment caching in ASP.NET is a technique used to cache a portion of a web page,


instead of the entire page. This type of caching can be useful when you have a page
that includes dynamic content, but also includes static content that does not change
frequently. By caching only the static content, you can reduce the amount of processing
required to generate the page, and improve the performance of your website.

To implement fragment caching in ASP.NET, you can use the asp:Substitution control.
The asp:Substitution control allows you to replace a portion of a page with cached
content. You can add the asp:Substitution control to your page, and use the
MethodName attribute to specify the name of a method that will generate the cached
content.

Here is an example of how to use fragment caching in ASP.NET:

<%@ Page Language="C#" %>

<%@ Import Namespace="System.Web.UI" %>

<%@ Import Namespace="System.Web.Caching" %>

<script runat="server">

public partial class ExamplePage : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)

public string GetStaticContent()

string staticContent = HttpRuntime.Cache["StaticContent"] as string;

if (staticContent == null)

staticContent = GenerateStaticContent();

HttpRuntime.Cache.Insert("StaticContent", staticContent, null,

DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration);

return staticContent;

private string GenerateStaticContent()

// Code to generate static content// ...return staticContent;

}
</script>

<html>

<head>

<title>Example Page</title>

</head>

<body>

<h1>Example Page</h1>

<asp:Substitution runat="server" MethodName="GetStaticContent" />

<p>This is some dynamic content that will not be cached.</p>

</body>

</html>

In this example, the GetStaticContent method is used to retrieve the cached content. If
the content is not in the cache, the GenerateStaticContent method is called to generate
the content. The content is then stored in the cache using the Insert method. The
asp:Substitution control is used to replace the portion of the page with the cached
content.

Fragment caching is not a silver bullet solution for improving performance. You should
carefully consider the trade-offs between improved performance and the added
complexity of caching. Additionally, you should test the performance of your website
with fragment caching enabled, to ensure that it meets your performance requirements.

ASP.NET offers a powerful feature called page fragment caching, which allows
developers to cache specific portions of a page, such as user controls. To utilize this
feature, you need to encapsulate the desired portion of the page into a user control.
Within the user control source file, you can include an OutputCache directive, specifying
the Duration and VaryByParam attributes to control the caching behavior. When the
user control is loaded into a page during runtime, it is cached, and subsequent pages
that reference the same user control will retrieve it directly from the cache, resulting in
improved performance and reduced server round trips.
15. Explain Client side state management

State Management techniques are based on client side and server side. Their
functionality differs depending on the change in state.

Client-Side State Management techniques are,

 View State

 Hidden field

 Cookies

 Control State

 Query Strings

View State

In general we can say it is used for storing user data in ASP.NET, sometimes in
ASP.NET applications the user wants to maintain or store their data temporarily after a
post-back.. In this case VIEW STATE is the most used and preferred way of doing that.

This property is enabled by default but we can make changes depending on our
functionality, what we need to do is just change the EnableViewState value to either
TRUE for enabling it or FALSE for the opposite operation.

Hidden Field

A hidden field is used for storing small amounts of data on the client side. In most
simple words it's just a container of some objects but their result is not rendered on our
web browser. It is invisible in the browser.
It stores a value for the single variable and it is the preferable way when a variable's
value is changed frequently but we don't need to keep track of that every time in our
application or web program.

Cookies

A set of Cookies is a small text file that is stored in the user's hard drive using the
client's browser. Cookies are just used for the sake of the user's identity matching as it
only stores information such as sessions id's, some frequent navigation or post-back
request objects.

Whenever we get connected to the internet for accessing a specific service, the cookie
file is accessed from our hard drive via our browser for identifying the user. The cookie
access depends upon the life cycle or expiration of that specific cookie file.

Persistent Cookie

Cookies having an expiration date is called a persistent cookie. This type of cookie
reaches their end as their expiration dates comes to an end

Non-Persistent Cookie

Non-persistent types of cookies aren't stored in the client's hard drive permanently. It
maintains user information as long as the user access or uses the services.

Control State

Control state is based on the custom control option. For expected results from
CONTROL STATE we need to enable the property of view state. As I already described
you can manually change those settings.

Query Strings

Query strings are used for some specific purpose. These in a general case are used for
holding some value from a different page and move these values to the different page.
The information stored in it can be easily navigated to one page to another or to the
same page as well.
16. What is Data Hiding? Explain Classes and Objects required in Data Hiding
in ASP.NET

Data hiding is a technique of hiding internal object details, i.e., data members. It is an
object-oriented programming technique. Data hiding ensures, or we can say guarantees
to restrict the data access to class members. It maintains data integrity.

Data hiding means hiding the internal data within the class to prevent its direct access
from outside the class.

If we talk about data encapsulation so, Data encapsulation hides the private methods
and class data parts, whereas Data hiding only hides class data components. Both data
hiding and data encapsulation are essential concepts of object-oriented
programming. Encapsulation wraps up the complex data to present a simpler view to
the user, whereas Data hiding restricts the data use to assure data security.

Data hiding also helps to reduce the system complexity to increase the robustness by
limiting the interdependencies between software components. Data hiding is achieved
by using the private access specifier.

Example: We can understand data hiding with an example. Suppose we declared


an Account class with a data member balance inside it. Here, the account balance is
sensitive information. We may allow someone to check the account balance but won't
allow altering the balance attribute. So, by declaring the balance attribute private, we
can restrict the access to balance from an outside application.

Now, let's discuss the access specifiers to understand the data hiding. Access specifiers
define how the member's functions and variables can be accessed from outside the
class. So, there are three access specifiers available within a class that are stated as
follows:
Private members/methods: Functions and variables declared as private can be
accessed only within the same class, and they cannot be accessed outside the class
they are declared.

Public members/methods: Functions and variables declared under public can be


accessed from anywhere.

Protected members/methods: Functions and variables declared as protected cannot


be accessed outside the class except a child class. This specifier is generally used in
inheritance.

// C# program to illustrate the

// concept of method hiding

using System;

// Base Class

public class My_Family {

public void member()

Console.WriteLine("Total number of family members: 3");

// Derived Class

public class My_Member : My_Family {


// Reimplement the method of the base class

// Using new keyword

// It hides the method of the base class

public new void member()

Console.WriteLine("Name: Rakesh, Age: 40 \nName: Somya, "+

"Age: 39 \nName: Rohan, Age: 20 ");

// Driver Class

class GFG {

// Main method

static public void Main()

// Creating the object of the derived class

My_Member obj = new My_Member();


// Access the method of derived class

obj.member();

}
17. Explain Server side state management

State Management is a process by which state and page information is maintained over
multiple requests for same or different pages. As HTTP is a stateless protocol, server
does not store any information once the

response is sent back to client based on his request. When user submits request again,
the server treats it as a new user. This is called stateless model. This model was
workable when static web sites were developed and hosted in the past. Now, with
interactive web sites or dynamic web site, there is a need to preserve some information
to identify user, interact with user again and again within same session and same
application. This concept is known as Stateful protocol. The information can be related
to user, data objects, web pages or server objects.

It is another way which ASP.NET provides to store the user's specific information or the
state of the application on the server machine. It completely makes use of server
resources (the server's memory) to store information.

This management technique basically makes use of the following,

a. Application State

b. Session State

Application State

1. If the information that we want to be accessed or stored globally throughout the


application, even if multiple users access the site or application at the same time,
then we can use an Application Object for such purposes.

2. It stores information as a Dictionary Collection in key - value pairs. This value is


accessible across the pages of the application / website.
3. There are 3 events of the Application which are as follows

o Application_Start

o Application_Error

o Application_End

Example

Just for an example, I am setting the Page title in the Application Start event of the
Global.asax file.

Code for setting value to the Application Object - "PageTitle" is the Key and "Welcome
to State Management Application" is the value.

Code for reading value from the Application Object

Session State
Session is one of the most common way which is being used by developers to maintain
the state of the application. The Session basically stores the values as a dictionary
collection in key/value pairs. It completely utilizes server resources to store the data. It
is a secure way of storing data, since the data will never be passed to the client.

For each and every user, a separate Session is created, and each and every Session
has its Unique ID. This ID is being stored in the client's machine using cookies. If there
are multiple users who are accessing a web application, then for each user a separate
Session is created. If a single user logs in and logs out the Session is killed, then if the
same user again logs into the application, then a new Session ID is being created for
the same user.

The Session has a default timeout value (20 minutes). We can also set the timeout
value for a session in the web.config file.

There are various ways in which we can store a session and they are as follows:

1. OFF

2. InProc

3. State Server

4. SQL Server

OFF

If we do not want to use sessions in our application, then we can set the mode as
"OFF".

InProc
This is the default mode which is used in ASP.NET to store session variables. InProc
mode basically stores the session value in the process in which the ASP.NET
application is running. Since it is stored in the same process, it provides high
performance as compared to other modes.

State Server

If we use this mode, then a separate Windows Service which runs in a different process
stores the Session. It basically isolates the Session from the ASP.NET running process.
It provides less performance as compared to the Inproc mode.

SQL Server

This mode stores the Session in SQL Server instead of the server's memory. If our
application is stored on multiple server machines, then it becomes difficult to use the
"Inproc" mode since the request can go to any server for processing. So if we want to
use sessions in such cases, then we can store the Session in SQL Server so that it
becomes centralized and can be accessed by any server during the request process. It
is the most secure way of storing Sessions but gives the lowest performance for an
application.

Code to write values into a Session

Code to read values from Session


18. Explain about the view state and hidden field in Client state management.

When a web application is developed, it is stateless by default. It means that values


present or filled in the controls is lost as soon as the web page is reloaded because
every time a page is requested by the client to the server, the page goes through a
series of processes in the server memory itself and once it is delivered to the
browser(client), the page is removed from the server memory. It happens because of a
single server, a new instance of the page is created every time it is requested, and
thereafter of all the controls of the web page. once it is delivered to the browser, all the
instances of the page elements are destroyed from the server memory. Therefore, to
retain those values in the controls, we use state management techniques like ViewState
and HiddenFields.Now, we will learn the difference between ViewState and
HiddenFileds.

ViewState

ViewState is a client-side state management technique. ViewState is used to store user


data on-page at the time of the postback of a web page.

ViewState holds the values of controls on a web page. It does not restore the value to
control after page postback. ViewState can hold the value on a single web page, if we
go to another page using response.redirect then the value in the ViewState will be lost.

 Please keep in mind though, that while cookies and sessions can be accessed
from all your pages on your website, ViewState values are not carried between
pages.

Storing values in ViewState:

ViewState[“name”]=”TutorialsLink”;

Retrieve value from ViewState:

string value=ViewState[“name”].ToString();
Hidden Fields

The hidden field technique is also a client-side state management technique used in
ASP.NET programming. Hidden fields are HTML input control with the hidden types that
store hidden data in the HTML.

Hidden fields store only one value in their valuable property. The value is saved as a
string and therefore in order to use it for other types you need to perform a casting
operation. Hidden fields' data is submitted to the server only in HTTP post-operation.
You can see the stored data easily by using the View Source operation of the browser
by clicking the right button of the mouse. You should avoid using hidden fields to store
confidential data as it can be accessed easily and it increases the chances of data to be
stolen!

The values in hidden fields have page context and therefore when you leave a page the
data stored in the hidden fields are destroyed.

Store values in Hidden Field

<asp:HiddenFieldID="Val1" runat="server" />

Setting values in Hidden Field by code

Val1.Value = DateTime.Now.ToString();

Retrieving value from Hidden Field

Val2.Text = Convert.ToString(Val1.Value);

The key differences between ViewState and HiddenFields:

ViewState hidden field

· ViewState is a secure method to ·HiddenFields is not a safe and secure


store data. method as the data value in it can be
seen and accessed very easily.

· ViewState can store large amounts ·Only a small amount of data can be
of data. stored.

· You can store more than one value · You can store more than one value
like Datatable and Dataset. in a hidden field, by serializing it.

·View state data is encrypted. · The data in HiddenField is not


encrypted.

·The data in the ViewState can not be · It is possible to change the value by
changed by Client-Side code,i.e, Client-side code in HiddenField.
JavaScript.
19. Define the Application state and Session state in Server state management.

The session state is used to maintain the session of each user throughout the
application. Session allows information to be stored in one page and access in another
page and support any type of object. In many websites we will see the functionality like
once if we login into website they will show username in all the pages for that they will
store username in session and they will access that session username in all the pages.

Whenever user enters into website new session id will generate for that user. This
session Id will delete when he leave from that application. If he enters again he will get
new session Id.

We can check this one with simple example for that create one new website and
open Default.aspx page and write the following code

protected void Page_Load(object sender, EventArgs e)


{

}
// Set Session values during button click
protected void btnSubmit_Click(object sender, EventArgs e)
{
Session["FirstName"] = txtfName.Text;
Session["LastName"] = txtlName.Text;
Response.Redirect("Default2.aspx");
}

Application state

ASP.Net Application state is a server side state management technique.


Application state is a global storage mechanism that used to stored data on the server
and shared for all users, means data stored in Application state is common for all
user. Data from Application state can be accessible anywhere in the application.
Application state is based on the System.Web.HttpApplicationState class.

The application state used same way as session state, but session state is specific for a
single user session, where as application state common for all users of asp.net
application.

Syntax of Application State

Store information in application state

 Application[“name”] = “Meera Academy”;

Retrieve information from application state

 string str = Application[“name”].ToString();

protected void btnvisit_Click(object sender, EventArgs e)

int count = 0;

if (Application["Visit"] != null)

count = Convert.ToInt32(Application["Visit"].ToString());

count = count + 1;

Application["Visit"] = count;

Label1.Text = "Total Visit = " + count.ToString();


}

Lock() and UnLock() in Application State

protected void btnvisit_Click(object sender, EventArgs e)

Application.Lock();

int cnt = 0;

if (Application["Visit"] != null)

cnt = Convert.ToInt32(Application["Visit"].ToString());

cnt = cnt + 1;

Application["Visit"] = cnt;

Application.UnLock();

Label1.Text = "Total Visit = " + cnt.ToString();

}
20. Explain UDDI.

UDDI is an XML-based standard for describing, publishing, and finding web services.

 UDDI stands for Universal Description, Discovery, and Integration.

 UDDI is a specification for a distributed registry of web services.

 UDDI is a platform-independent, open framework.

 UDDI can communicate via SOAP, CORBA, Java RMI Protocol.

 UDDI uses Web Service Definition Language(WSDL) to describe interfaces to


web services.

 UDDI is seen with SOAP and WSDL as one of the three foundation standards of
web services.

 UDDI is an open industry initiative, enabling businesses to discover each other


and define how they interact over the Internet.

UDDI has two sections −

 A registry of all web service's metadata, including a pointer to the WSDL


description of a service.

 A set of WSDL port type definitions for manipulating and searching that registry.

Private UDDI Registries

As an alternative to using the public federated network of UDDI registries available on


the Internet, companies or industry groups may choose to implement their own private
UDDI registries. These exclusive services are designed for the sole purpose of allowing
members of the company or of the industry group to share and advertise services
amongst themselves. Regardless of whether the UDDI registry is a part of the global
federated network or a privately owned and operated registry, the one thing that ties
them all together is a common web services API for publishing and locating businesses
and services advertised within the UDDI registry.

At its heart, UDDI is a database that’s searchable by type of business (typically


identified using the North American Industry Classification System—NAICS—or the
Standard Industrial Classification), business name or geographical location.

Let’s say you have an electronic order-entry system that relies on SOAP-based Web
services and you want to do online business with computer makers. You’ll first need to
know which computer makers have compatible Web services. A search of UDDI would
return a list of those computer companies that have registered with the system.

UDDI registration is open to companies worldwide. When a business registers with


UDDI, it provides the registry with “white pages” information about itself (including items
such as name and contact info), “yellow pages” taxonomies (including NAICS business
identifiers, products, services and geographic location) and “green pages” information
describing the company’s business processes and how to do business with it.
21. Explain the Database access in ASP.NET. Describe Data Source Control.

Database access

SqlDataSource control is a data source control provided in ASP.NET to connect to


database providers such as SQL, OLEDB, ODBC, and Oracle. This control only
establishes a connection with the data source; it does not display data on the web page.
The data is displayed by binding the SqlDataSource control to a data-bound control
such as a GridView or DataList. These data-bound controls, in turn, display the data on
the web page. The SqlDataSource control also supports editing, updating, deleting, and
sorting of the records retrieved from the database. This support to manipulate the data
in the data source can be implemented in data-bound controls without writing any code.
In other words, a SqlDataSource control allows you to access databases without
creating a Connection, Command, or a Data Reader object.

Adding SqlDataSource Control

A SqlDataSource control is added to the webform using markup or by dragging it from


the Toolbox and dropping it on the web form. The code below shows the markup to
create a SqlDataSource control.

<asp:SqlDataSource ID=”sqldsSuppliers” runat=”server”>

</asp:SqlDataSource>

ASP.NET (C#)

Copy

The markup in this code creates a SqlDataSource control named sqldsSuppliers. This
control will be used to connect to the NWSuppliers table in the Northwind database.

Configuring SqlDataSource Control


The basic configuration of the SqlDataSource control involves setting two attributes,
namely ConnectionString and SelectCommand. The ConnectionString attribute
specifies the connection string to connect to a particular database. The SelectCommand
attribute specifies the select statement to retrieve the records from a database table.
Source code uses these attributes to connect to the Northwind database located on the
SQL Server instance, SQLEXPRESS, installed on the system 10.2.1.51.

<asp:SqlDataSource ID=”sqldsSuppliers” runat=”server” ConnectionString=”Data


Source=10.2.1.51\SQLEXPRESS;Initial Catalog=Northwind; Integrated Security=True”
SelectCommand=”select * from NWSupplierss;”>

</asp:SqlDataSource>

ASP.NET (C#)

Copy

The SqlDataSource control, sqldsSuppliers, will retrieve all the records from the
NWSuppliers table.

The attribute ConnectionString and SelectCommand are available only in the Source
view of the web form in design view, the selectCommand attribute is available as a
SelectQuery property.

Binding to a Data Bound Control

After the SqlDataSource control is configured to retrieve data from the database, it is
bound to a data-bound control. The code below shows the code to bind an
SQqlDataSource control named sqldsSuppliers to a DataList control named
dlstSuppliers using the DataSourceID property.

<asp:DataList ID=”dlstSuppliers” runat=”server” backcolor=”LightGoldenrodYellow”


BorderColor=”Tan” BorderWidth=”1px” CellPadding=”2” DataSourceID=”sqldsSuppliers”
Font-Name=”verdana” Font-Size=”Smaller” ForeColor=”Black”>

</asp:Datalist>
ASP.NET (C#)

Copy

The same SqlDataSource control can be bound to another data-bound control such as
the GridView control by setting the DataSourceID property to sqldsSuppliers. Code
shows the ItemTemplate code to display the data in a DataList control named
dlstSuppliers.

<ItemTemplate>

<strong>Supplier ID </strong>

<asp:Label ID=”lblSupplierID” runat=”server” Text=’<%#Eval(“SupplierID”)%>’


width=”45px” Font-size=”x-small”>

</asp:Label> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; <strong> Company Name:</strong>

<asp:Label ID=”lblCompanyName” runat=”server” Test=’<%#Eval(“Companyname”)


%>’ width=”197px” Font-size=”x-small”>

</asp:Label>

<br />

<br />

<strong> Contact Name:</strong>

<asp:Label ID=”lblContactName” runat=”server” Test=’<%#Eval(“ContactName”)%>’


width=”127px” Font-size=”x-small” Font-Bold=”False”>

</asp:Label>

<br />

<br />
<strong> Phone:</strong>

<asp:Label ID=”lblPhone” runat=”server” Test=’<%#Eval(“Phone”)%>’ width=”111px”


Font-size=”xx-small” Font-Bold=”False”>

</asp:Label>

<br />

<br />

</ItemTemplate>

<AlternatingItemStyle BackColor=”PaleGoldenrod” />

ASP.NET (C#)

Copy

The ItemTemplate in the source code comprises four times. It displays four textual
labels namely Supplier ID, Company name, Contacts Name, and Phone. The
ItemTemplate also has four corresponding Label controls namely lblSupplierID,
lblCompanyName, lblContactName, and lblPhone respectively. These Label controls
are bound to the columns SupplierID, CompanyName, ContactName, and Phone
respectively of the NWSuppliers table.

Commands in SqlDataSource Control

The SqlDataSource control uses the SelectCommand property to retrieve the records
from a database table. Similarly, SqlDataSource control is provided with
DeleteCommand, UpdateCommand, and InsertCommand properties to delete, update
and add a new record into a database table.

DeleteCommand Property

The DeleteCommand property is used to specify the DELETE statement to delete a


record. DeleteCommand is available as an attribute of the SQLDataSource tag in
source view. In the Design view, the DELETE statement is specified as a value of the
property, DeleteQuery. Source code shows in bold how to set the DeleteCommand
attribute of the SqlDataSource tag.

<asp:SqlDataSource ID=”sqldssuppliers” runat=”server” ConnectionString=”Data


Source=10.2.1.51\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=”True”
SelectCommand=”Select * from NWSuppliers ;”DeleteCommand=”delete from
NWSuppliers where SupplierID=@SupplierID” >

<DeleteParameters>

<asp:Parameter Type=”Int32” Name=”SupplierID” />

</DeleteParameters>

</asp:SqlDataSource>

ASP.NET (C#)

Copy

The DeleteCommand in code contains a placeholder, @SupplierID, for SupplierID


value. The details about this placeholder are specified by the <DeleteParameters>
element. This data source control can now be used with a data-bound control such as a
DataList control.

If the SqlDataControl is used with a GridView control, you can provide delete
functionality by setting two properties. The DataSource property is set to sqldsSuppliers
and the DataKeyNames property is set to SupplierID.

The steps to be followed in order to implement delete functionality in the DataList


control, dlstSuppliers are listed below:

In the Properties window of the dlstSuppliers control, set the DatakeyField property to
the primary key column of the database table, NWSuppliers. In this case, you set it to
SupplierID. The DataKeyField attribute specifies the name of the primary key column,
which is used to delete or update a record in the database table.
AccessDataSource Control

Designed to work with Microsoft Access. It uses OleDb data provider internally. OleDb
data provider classes are defined in the System.Data.OleDb namespace. The
AccessDataSource class is a data source control that works with Microsoft Access
databases. Like its base class, SqlDataSource, the AccessDataSource control uses
SQL queries to perform data retrieval.

One of the unique characteristics of the AccessDataSource control is that you do not set
the ConnectionString property. All you need to do is set the location of the Access
(.mdb) file in the DataFile property and the AccessDataSource takes care of the
underlying connection to the database. You should place Access databases in the
App_Data directory of the Web site and reference them by a relative path (for example,
~/App_Data/Test.mdb). This location offers additional security for data files, because
they are not served if they are requested directly by the client Web browser. You bind
data-bound controls to an AccessDataSource using the DataSourceID property of the
data-bound control.

The following are the features of the AccessDataSource control.

 Sorting - Set the DataSourceMode property to the DataSet value.


 Filtering - Set the FilterExpression property to a filtering expression used to filter
the data when the Select method is called.
 Paging - The AccessDataSource does not support direct paging operations on an
Access database. A data-bound control, such as the GridView, can page over
the items returned by the AccessDataSource, if the DataSourceMode property is
set to the DataSet value.
 Updating - Set the UpdateCommand property to a SQL statement used to update
data. This statement is typically parameterized.
 Deleting - Set the DeleteCommand property to a SQL statement used to delete
data. This statement is typically parameterized.
 Inserting - Set the InsertCommand property to a SQL statement used to insert
data. This statement is typically parameterized.
 Caching - Set the DataSourceMode property to the DataSet value, the
EnableCaching property to true, and the CacheDuration and
CacheExpirationPolicy properties according to the caching behavior you want for
your cached data.
22. What is a web service? Explain HTTP Request, HTTP Response and
methods for submitting information in HTTP Request.

With Web Services, you can reuse someone else's business logic instead of replicating
it yourself, using just a few lines of code. This technique is similar to what programmers
currently do with libraries of APIs, DLLs or plug-ins. The main difference is that Web
Services can be located remotely on another server.

When HTML pages (or the HTML output generated by ASP.NET web forms) are
rendered in a browser for the end user, Web Services are invoked by other applications.
They are pieces of business logic that are hosted somewhere on the internet and can
be accessed by other applications.

Note 1: Web Services are not limited to the .NET Framework. The standards were
defined before .NET was released and they are exposed, used and supported by
vendors other than Microsoft.
Note 2: Web Services are cross-platform; a service written in one language can be
invoked by an application in some other language. The only requirement for accessing a
service is an internet connection to make the HTTP request.

Since a web service is cross-platform, there should be some commonly understandable


language for requesting a service and getting a response from the service. Such a
standard common language is XML. That's why Web Services are built on XML-based
standards for exchanging data.

As a result, the set of data types Web Services can use is limited to the set of data
types recognized by the XML Schema standard. So you can use simple data types such
as strings and numbers to communicate with a web service and you can't send
proprietary .NET objects such as a FileStream, an Image or an EventLog. This
restriction makes a lot of sense. Since other programming languages have no way to
interpret these .NET objects, even if you could devise a way to send them over the wire,
the client might not be able to interpret them, that would thwart interoperability.

Note 3: If you need to work with .NET proprietary objects, you can go for .NET
remoting. It is a distributed technology that allows use of .NET objects. But non-.NET
clients can't consume it.
Here's the list of supported data types
 Built-in types (The Basics): The built in C# data types such as short, int, long,
ushort, uint, ulong, float, double, decimal, bool, string, char, byte and DateTime.
 Objects: You can use an object of any user defined class. If your class has
methods, these methods will not be transmitted to the client.
 Arrays: Arrays of any supported type (built-in or custom objects). You can also use
an ArrayList (that is simply converted into an array).
 Enumerations: Enums are supported. However, a web service uses the string
name of the enumeration value, not the underlying integer.
 XmlNode: Objects based on System.Xml.XmlNode represent a portion of an XML
document. You can use this to send arbitrary XML.
 DataSet and DataTable : DataSet and DataTable are allowed. But other ADO.NET
data objects, such as DataColumns and DataRows, aren't supported.
Create a web service

Let's create a simple service that will return a sum of 2 integers.

Open Visual Studio in Administrator mode. File → New → Project then select .Net
Framework 3.5 (on the top) then select ASP.NET web service application then name
your project (I named it MyWebServiceDemo) then click OK.
Visual Studio will create a web service boilerplate (Service1.asmx and
Service1.asmx.cs) for you. Now, let's analyze this template created by Visual Studio.

Note the following In Service1.asmx.cs:

1. An additional namespace “System.Web.Services” is included along with the 4


default namespaces that Visual Studio includes for web application.

2. The “Service1” class is inherited from “System.Web.Services.WebService”. By


inheriting a class from “System.Web.Services.WebService”, you can access built-
in ASP.NET objects such as (Application, Session, User, Context, server). If you
don't need built-in objects of .Net, you don't need to inherit your service class from
“WebService”.

3. “Service1” is decorated with a “WebService(Namespace = "http://tempuri.org/" )”


attribute. If you want to expose a class as a service, you need to decorate it with the
“WebService” attribute. This WebService attribute has several properties like:
o Namespace: This property makes a service uniquely identifiable. This is an
XML property. A client application may be consuming several services, so there
is the probability of a naming collision. To avoid this, it's service providers
responsibility to use a unique namespace.
o Name: Use this property to provide a descriptive name to your service.
o Description: To provide a brief description on the service.

4. “Service1” has another attribute “WebServiceBinding(ConformsTo


= WsiProfiles.BasicProfile1_1)”. This is to indicate the standard which service is
following. If the service does not confirm to this standard, you will get an exception.

5. One more attribute service is decorated with is


“[System.Web.Script.Services.ScriptService]”, to make a service accessible from
the client script, it should be decorated with this attribute.

6. The Service1 class has a method HelloWorld that is decorated with a


“[WebMethod]” attribute. The methods of the service that are to be accessed by the
client application should be decorated with this attribute. There may be some
method that the service is using for some internal functionality, client applications
don't need to access them. Don't decorate such methods with a WebMethod
attribute. The WebMethod attribute also has Name and Description properties that
you can use to provide a self describing name or description respectively.
23. Explain ADO.NET Object Model.

Most applications need to handle data, whether it is in the form of a dataset, a text file,
or a spreadsheet. The majority of modern-day applications need to deal with various
types of databases. Therefore, to access this data the application needs to interact with
various databases, such as Microsoft SQL Server, Oracle, Microsoft Access and so on.

ADO.NET is a large set of .NET classes that enable us to retrieve and manipulate data,
and update data sources, in very many ways. As an integral part of the .NET
framework, it shares many of its features; features such as multi-language support,
garbage collection, just-in-time compilation, object-oriented design, and dynamic
caching, and is far more than an upgrade of previous versions of ADO. ADO.NET is set
to become a core component of any data-driven .NET application or Web Service, and
understanding its power will be essential to anyone wishing to utilize .NET data support
to maximum effect.

The ADO.NET object model consists of two key components as follows:

 Connected model (.NET Data Provider - a set of components including the


Connection, Command, DataReader, and DataAdapter objects)

 Disconnected model (DataSet).

Connection

The Connection object is the first component of ADO.NET. The connection object
opens a connection to your data source.

All of the configurable aspects of a database connection are represented in the


Connection object, which includes ConnectionString and ConnectionTimeout.

Connection object helps in accessing and manipulating a database. Database


transactions are also dependent upon the Connection object.
In ADO.NET the type of the Connection is depended on what Database system you
are working with. The following are the commonly used connections in the
ADO.NET

 SqlConnection

 OleDbConnection

 OdbcConnection

Command

The Command object is used to perform an action on the data source. Command
object can execute stored procedures and T-SQL commands.

You can execute SQL queries to return data in a DataSet or a DataReader object.
Command object performs the standard Select, Insert, Delete, and Update T-SQL
operations.

DataReader

The DataReader is built as a way to retrieve and examine the rows returned in
response to your query as quickly as possible.

No DataSet is created; in fact, no more than one row of information from the data
source is in memory at a time. This makes the DataReader quite efficient at
returning large amounts of data.

The data returned by a DataReader is always read-only. This class was built to be
a lightweight forward-only, read-only, way to run through data quickly (this was
called a firehose cursor in ADO).

However, if you need to manipulate schema or use some advanced display features
such as automatic paging, you must use a DataAdapter and DataSet.

DataReader object works in a connected model.


DataAdapter

The DataAdapter takes the results of a database query from a Command object and
pushes them into a DataSet using the DataAdapter.Fill() method. Additionally the
DataAdapter.Update() method will negotiate any changes to a DataSet back to the
original data source.

DataAdapter object works in a connected model. DataAdapter performs the five


following steps:

1. Create/open the connection

2. Fetch the data as per command specified

3. Generate XML file of data

4. Fill data into DataSet.

5. Close connection.

Command Builder

It is used to save changes made in an in-memory cache of data on the backend.


The work of Command Builder is to generate Command as per changes in
DataRows.

Command Builder generates command on basis of row state. There is a five-row


state:

1. Unchanged

2. Added

3. Deleted

4. Modified

5. Detached
Command Builder works on add, delete, and modified row state only.

Detached is used when an object is not created from row state.

Transaction

The Transaction object is used to execute the backend transaction. Transactions


are used to ensure that multiple changes to database rows occur as a single unit of
work.

The Connection class has a BeginTransaction method that can be used to create a
Transaction.

A definite best practice is to ensure that Transactions are placed in Using


statements for rapid cleanup if they are not committed. Otherwise, the objects (and
any internal locks that may be needed) will remain active until the GC gets around to
cleaning it up.

Parameters

Parameter object is used to solve the SQL Injection attack problem while dealing
with the user input parameters.

Parameter object allows passing parameters into a Command object the Parameter
class allows you to quickly put parameters into a query without string concatenation.
24. Explain the role of Simple Object Access Protocol in web services.

OAP stands for Simple Object Access Protocol is a network platform used in a web
service to exchange or communicate data between two different machines on a
network. It uses the XML format of data to transfer messages over the HTTP protocol.
In Web services, SOAP allows the user request to interact with other programming
languages. In this way, it provides a way to communicate between applications running
on different platforms (Operating system), with programming languages and
technologies used in web service.

SOAP Message:

The SOAP message contains the following information in the XML format, as given
below.

o It contains information about the message structure and instructions during


processing on the network.

o The SOAP contains an envelope that represents the starting and end of the
message in the XML format.
o In the message, the header is an optional element that contains application-
specific information such as authentication, authorization, and payment etc.

o A fault element is an optional element that shows an error message during the
processing of the information.

Characteristics of SOAP

o It is an open standard protocol used in the web service to communicate via


internet.

o It is used to broadcast a message over the network.

o It is used to call remote procedures and exchange documents.

o It can be used on any platform and can support multi-languages. So, it is a


platform and language independent.

o It uses the XML format to send messages over the HTTP protocol.

o The structure of a SOAP message consists of an envelope, header, and body


element.
25. What is SOAP (Simple Object Access protocol.) in web services?

The SOAP specification defines something known as a “SOAP message” which is what
is sent to the web service and the client application.

The below diagram of SOAP architecture shows the various building blocks of a SOAP
Message.

SOA
P Message Building Blocks
The SOAP message is nothing but a mere XML document which has the below
components.
 An Envelope element that identifies the XML document as a SOAP message –
This is the containing part of the SOAP message and is used to encapsulate all
the details in the SOAP message. This is the root element in the SOAP
message.
 A Header element that contains header information – The header element can
contain information such as authentication credentials which can be used by the
calling application. It can also contain the definition of complex types which could
be used in the SOAP message. By default, the SOAP message can contain
parameters which could be of simple types such as strings and numbers, but can
also be a complex object type.

A simple SOAP service example of a complex type is shown below.

Suppose we wanted to send a structured data type which had a combination of a


“Tutorial Name” and a “Tutorial Description,” then we would define the complex type as
shown below.

The complex type is defined by the element tag <xsd:complexType>. All of the required
elements of the structure along with their respective data types are then defined in the
complex type collection.

<xsd:complexType>
<xsd:sequence>
<xsd:element name="Tutorial Name" type="string"/>
<xsd:element name="Tutorial Description" type="string"/>
</xsd:sequence>
</xsd:complexType>

 A Body element that contains call and response information – This element is
what contains the actual data which needs to be sent between the web service
and the calling application. Below is an SOAP web service example of the SOAP
body which actually works on the complex type defined in the header section.
Here is the response of the Tutorial Name and Tutorial Description that is sent to
the calling application which calls this web service.

<soap:Body>
<GetTutorialInfo>
<TutorialName>Web Services</TutorialName>
<TutorialDescription>All about web services</TutorialDescription>
</GetTutorialInfo>
</soap:Body>
26. Describe the xml elements and naming rules in xml.

An XML (EXtensible Markup Language) Document contains declarations, elements,


text, and attributes. It is made up of entities (storing units) and It tells us the structure of
the data it refers to. It is used to provide a standard format of data transmission. As it
helps in message delivery, it is not always stored physically, i.e. in a disk but generated
dynamically but its structure always remains the same.

XML Standard structure and its rules:

Rule 1: Its standard format consists of an XML prolog which contains both XML
Declaration and XML DTD (Document Type Definition) and the body. If the XML prolog
is present, it should always be the beginning of the document. The XML Version, by
default, is 1.0, and including only this forms the shortest XML Declaration. UTF-8 is the
default character encoding and is one of seven character-encoding schemes. If it is not
present, it can result in some encoding errors.

Rule 2: XML Documents must have a root element (the supreme parent element) and
its child elements (sub-elements). To have a better view of the hierarchy of the data
elements, XML follows the XML tree structure which comprises of one single root
(parent) and multiple leaves (children).

Rule 3: All XML Elements are required to have Closing and opening Tags(similar to
HTML).

Rule 4: The opening and closing tags are case-sensitive. For Example, <Message> is
different from <message> from above example.
Rule 5: Values of XML attributes are required to have quotations:
Rule 6: White-Spaces are retained and maintained in XML.

Rule 7: Comments can be defined in XML enclosed between <!– and –> tags.
Rule 8: XML elements must be nested properly.

XML Naming Rules

XML elements must follow these naming rules:

Element names are case-sensitive

Element names must start with a letter or underscore

Element names cannot start with the letters xml (or XML, or Xml, etc)

Element names can contain letters, digits, hyphens, underscores.

Element names cannot contain spaces


27. What is XML? Describe characteristics and uses of XML. How it is different
from HTML

HTML (Hyper Text Markup Language) is used to create web pages and web
applications. It is a markup language. By HTML we can create our static page. It is
used for displaying the data not to transport the data.
HTML is a combination of Hypertext and Markup language. Hypertext defines the link
between the web pages. A markup language is used to define the text document
within the tag which defines the structure of web pages. This language is used to
annotate (make notes for the computer) text so that a machine can understand it and
manipulate text accordingly.

XML:
XML (Extensible Markup Language) is a versatile markup language designed for
carrying and storing data. It allows users to define their custom tags, making it highly
flexible. XML is often used for data interchange between different systems, enabling
the sharing of structured information.
XML is also used to create web pages and web applications. It is dynamic because it
is used to transport the data not for displaying the data. The design goals of XML
focus on simplicity, generality, and usability across the Internet. It is a textual data
format with strong support via Unicode for different human languages. Although the
design of XML focuses on documents, the language is widely used for the
representation of arbitrary data structures such as those used in web services.

HTML XML
It was written in 1993. It was released in 1996.
HTML stands for Hyper Text Markup XML stands for Extensible Markup
Language. Language.
HTML is static in nature. XML is dynamic in nature.
It was developed by WHATWG. It was developed by Worldwide Web
Consortium.
It is termed as a presentation It is neither termed as a presentation
language. nor a programming language.
HTML is a markup language. XML provides a framework to define
markup languages.
HTML can ignore small errors. XML does not allow errors.
It has an extension of .html and .htm It has an extension of .xml
HTML is not Case sensitive. XML is Case sensitive.
HTML tags are predefined tags. XML tags are user-defined tags.
There are limited number of tags in XML tags are extensible.
HTML.
HTML does not preserve white White space can be preserved in
spaces. XML.
HTML tags are used for displaying XML tags are used for describing
the data. the data not for displaying.
In HTML, closing tags are not In XML, closing tags are necessary.
necessary.
HTML is used to display the data. XML is used to store data.
HTML does not carry data it just XML carries the data to and from the
displays it. database.
HTML offers native object support. IN XML, the objects are expressed
by conventions using attributes.
HTML document size is relatively XML document size is relatively
small. large as the approach of formatting
and the codes both are lengthy.
An additional application is not DOM(Document Object Model) is
required for parsing of JavaScript required for parsing JavaScript
code into the HTML document. codes and mapping of text.
Some of the tools used for HTML Some of the tools used for XML are:
are:  Oxygen XML
 Visual Studio Code  XML Notepad
 Atom  Liquid Studio
 Notepad++ and many more.
 Sublime Text
and many more.
28. Explain Data Caching with example

What is Data Cache?


Data Cache is used to storing frequently used data in the Cache memory. It's much
efficient to retrieve data from the data cache instead of database or other sources. We
need use System.Web.Caching namespace. The scope of the data caching is within the
application domain unlike "session". Every user can able to access this objects.
How data caching is work?
When client request to the server, server execute the stored procedure or function or
select statements on the Sql Server database then it returns the response to the
browser. If we run again same process will happen on the web server with sql server.
In the very first time retrieve the records from the sql server database and stored into
the Cache memory. After that records will retrieve from Cache memory (IIS). We can
set expiration period time after expiration time over the caching again it will hit the sql
server database and stored into the cache memory and next retrieve will happen on the
data cache memory.
Advantages of Cookies
Following are main advantages of using cookies in web application:
 It's very simple to use and implement.
 We can avoid database hitting.
 We can reduce network traffic.
How to create data cache?
Cache["Employee"] = "DataSet Name"
We can create data caching use Cache Keyword. It's located in the
System.Web.Caching namespace. It's just like assigning value to the variable
How to Read data from Data Cache?
Dataset dsEmployee = (Dataset) Cache ["Employee"]
This is very similar to assigning object to the Dataset.
Where does Data Cache are stored?
This is one of the interesting things to find out the Data Caching in your local drive. First
of all, From "IE Internet Option ", delete Browsing History to clear Cache.
How to remove a Data Cache?
We can remove Data Cache manually.

//We need to specify the cache name

Cache.Remove(String key);
Example:
TimeSpan ts =
new TimeSpan(0, 0, 10);
//If cache has null, it will create two cache
and it will bind into the gridview
if (Cache["Employee"] == null)
{
dtEmployee = new DataTable("Employee");
dtEmployee.Columns.Add("EmpID", typeof(int));
dtEmployee.Columns.Add("EmpName", typeof(string));
DataRow rs = dtEmployee.NewRow();
rs[0] = 10;
rs[1] = "Annathurai";
dtEmployee.Rows.Add(rs);

//To assign datatable to cache memory.


Cache["Employee"] = dtEmployee;
Cache.Insert("Employee", dtEmployee, null, Cache.NoAbsoluteExpiration, ts);
Response.Write("Its processing with Database hit");
}
else
{
//If cache has value, It retrive from cache memory and bind into the
gridview
Response.Write("Its processing from cache");
}
/Here we are converting cache into datatable
GridView1.DataSource = (DataTable)Cache["Employee"];
GridView1.DataBind();
29. What is a .Net Assembly? Explain different kind of Assemblies

Assembly is an important concept in C#. It is a collection of code files that are compiled
into an executable or a Dynamic Link Library (DLL). Depending on their location and
intended use, assemblies can be divided into many categories.

Assemblies are an important part of the .NET framework and are used to store code
files and resources that can be used by one or more applications. There are four main
types of assemblies in C#: Private Assemblies, Shared Assemblies, Satellite
Assemblies, and Dynamic Link Libraries (DLLs). Each type of assembly has its own
purpose and usage.

Private Assemblies:

An Assembly that is solely used by one application is referred to as a Private Assembly.


It is typically found in the directory for the application or a subdirectory of the directory
for the programme. Private Assemblies are not intended to be shared with other
applications. They are used to store application-specific code and resources.

Private Assemblies are created when an application is compiled. When an application is


compiled, all the code files and resources that are used by the application are compiled
into a single assembly.The application's directory or a subdirectory of the application's
directory will thereafter contain this assembly.

Private Assemblies are simple to deploy and use. They don't need any extra installation
or setting. They are automatically loaded by the .NET runtime when the application
starts.
Shared Assemblies:

An assembly that is used by several programmes is referred to as a shared assembly. It


is typically found in the Global Assembly Cache (GAC) or a common directory.
Multiple applications are supposed to share a shared assembly. They are used to store
resources and code that are shared by various applications.

Shared Assemblies are created using the strong name tool (sn.exe). A digital signature
for the assembly is applied using the strong name tool. The digital signature guarantees
that the assembly is genuine and unaltered.

The Global Assembly Cache (GAC) houses shared assemblies. Shared assemblies
are kept in the GAC, which serves as a central repository. The GAC location is in the
Windows directory (C:\Windows\assembly). Shared assemblies are registered with
the GAC using the gacutil.exe tool.

Shared assemblies require special configuration and installation. They cannot be simply
copied to the application's directory. They need to be registered with the GAC using
the gacutil.exe tool.

Satellite Assemblies:

An assembly used to store regional resources is referred to as a Satellite Assembly. It is


typically found in a subdirectory of the directory for the application or a subdirectory of
the directory for the Shared Assembly. Localized resources like strings, pictures, and
audio files are kept in satellite assemblies.

Satellite Assemblies are created using the resgen.exe tool. The resgen.exe tool is
used to create a resource file (.resx) from a text file. The resource file is then compiled
into a satellite assembly using the al.exe tool.

You might also like