ASP.net
ASP.net
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 works on top of the HTTP protocol, and uses the HTTP commands and
policies to set a browser-to-server bilateral communication and cooperation.
The ASP.NET application codes can be written in any of the following languages:
C#
Visual Basic.Net
Jscript
J#
ASP.NET Features
o Server Controls
o Master Pages
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.
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.
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
Performance
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 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.
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.
1. <div>
3. </div>
Mode Description
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.
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.
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.
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 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
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
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.
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 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
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
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:
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:
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:
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.
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";
// open connection
conn.Open();
while (reader.Read())
{
Console.Write("OrderID :" + reader.GetInt32(0).ToString());
Console.Write(" ,");
Console.WriteLine("Customer: " + reader.GetString(1).ToString());
}
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:
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.
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.
14. Environment ADO was geared for a two- ADO.NET address a multi-tiered
tiered architecture. architecture.
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.
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.
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.
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 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.
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
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 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:
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.
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.
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.
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.
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.
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 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.
24/7 uptime
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.
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.
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:
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.
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.
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.
<script runat="server">
{
protected void Page_Load(object sender, EventArgs e)
if (staticContent == null)
staticContent = GenerateStaticContent();
DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration);
return staticContent;
}
</script>
<html>
<head>
<title>Example Page</title>
</head>
<body>
<h1>Example Page</h1>
</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.
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.
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.
using System;
// Base Class
// Derived Class
// Driver Class
class GFG {
// Main method
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.
a. Application State
b. Session State
Application State
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.
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.
ViewState
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.
ViewState[“name”]=”TutorialsLink”;
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.
Val1.Value = DateTime.Now.ToString();
Val2.Text = Convert.ToString(Val1.Value);
· 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.
·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
}
// 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
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.
int count = 0;
if (Application["Visit"] != null)
count = Convert.ToInt32(Application["Visit"].ToString());
count = count + 1;
Application["Visit"] = count;
Application.Lock();
int cnt = 0;
if (Application["Visit"] != null)
cnt = Convert.ToInt32(Application["Visit"].ToString());
cnt = cnt + 1;
Application["Visit"] = cnt;
Application.UnLock();
}
20. Explain UDDI.
UDDI is an XML-based standard for describing, publishing, and finding web services.
UDDI is seen with SOAP and WSDL as one of the three foundation standards of
web services.
A set of WSDL port type definitions for manipulating and searching that registry.
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.
Database access
</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.
</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.
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>
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>
<strong> Company Name:</strong>
</asp:Label>
<br />
<br />
</asp:Label>
<br />
<br />
<strong> Phone:</strong>
</asp:Label>
<br />
<br />
</ItemTemplate>
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.
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
<DeleteParameters>
</DeleteParameters>
</asp:SqlDataSource>
ASP.NET (C#)
Copy
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.
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.
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.
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
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.
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.
Connection
The Connection object is the first component of ADO.NET. The connection object
opens a connection to your data source.
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.
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.
5. Close connection.
Command Builder
1. Unchanged
2. Added
3. Deleted
4. Modified
5. Detached
Command Builder works on add, delete, and modified row state only.
Transaction
The Connection class has a BeginTransaction method that can be used to create a
Transaction.
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 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 uses the XML format to send messages over the HTTP protocol.
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.
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.
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.
Element names cannot start with the letters xml (or XML, or Xml, etc)
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
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);
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:
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:
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:
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.