CH 1 - Introduction of
CH 1 - Introduction of
Net
What is ASP?
ASP is known as Active Server Pages which is produced by Microsoft Team in the early of year
1990. Microsoft Active Server Pages (ASP) is allowed us to build dynamic and interactive web
applications. ASP classic is easily to let web application link to database inside the web
application. The web application created by ASP does not affect by using different type of the
web browser. The file extension for ASP is .asp. Example: http://www.asp.com/test.asp.
The default programming language to build ASP web site is using VBscript to buid, but it is
support other programming languages like JSscript (JavaScript from Microsoft). But ASP.net
allows web developer use either visual basic (VB) or ASP.net language to build the web
applications.
What is Web server?
Web servers are the tool that can manage web application that built by the web developers and
make all the web application available to the client web browser. It can success connected
through a local network or over the Internet (two different machines or same machine). While
there are many Web servers available which one of the common ones is Apache, Internet
Information Services (IIS), and iplanet Enterprise Server. (DotNetNuke, 2009)
To test or run ASP.NET Web applications, you need a Web server
Internet Information Services (IIS)
IIS Web server comes bundled with Windows 2000, Windows XP Professional, and Windows
Server 2003.
How does ASP work?
An ASP page is stored at server-side. So, client cannot simply view an ASP page on the web
browser. They need to request the ASP page through the web server which is supports for ASP.
When a client request an ASP page through the web browser, the web server will locates the
ASP file on the hard drive and interpret it. After that, it will remove all the ASP Script and
replace them with HTML Text.
Web server locates the ASP file and replace with HTML text and send back to the web browser.
Problem with ASP Classic
ASP is using html controls to interact with the user. Although ASP is having few good functions
to build web application, it still not perfect yet to satisfy web developer in some of the areas.
For example, ASP needs to code all the things in a single web page including the functions and
interface. It is not very convenience when need to modify or update some of the data on the
web page.
Besides that, another disadvantages using ASP classic to build web page is lack of the
performance and scalability, which means the web page that built by ASP classic will not auto
fix the web pages with the web browser. The layout of the web page will out of the margin and
the content cannot show as what web developer have designed for.
How does ASP.net work?
Think of ASP.NET web pages as normal HTML pages that have sections marked up for special
consideration. When .NET is installed, IIS Web server on the local machine will automatically to
check for files with the extension .aspx and it will use the ASP.NET module that have a a file
called aspnet_isapi.dll to handle them.
First of all, the client requests the web page from the web server. Then the web server started
to locates the instruction file. Meanwhile, the ASP.net code is sent to the Common Language
Runtime for compilation. After that, the HTML stream returned to the web browser. After the
web browser get the HTML code. It will processes the HTML code and display the content of the
page to the client.
ASP.NET compared with ASP Classic
Now, I will differentiate the asp version between ASP.net and ASP classic. What are the changes
in ASP.net instead of the ASP classic and what is the improvement from ASP classic. Besides, I
am also focus on what are the new features in ASP.net.
First of all, the mainly ASP.net difference from ASP classic is ASP.net is ASP.net is support more
language for scripting. For example, Asp.net supports visual basic language, C#, C++, Jscript and
ADO.net as well. Support multiple languages will getting more web developer choose ASP.net
as their first choice to develop a web page and web applications and let different background
programmer can work together by using a same application.
Besides, there are few points to compare between ASP.net and ASP classic. One of the aspects
is compilation. ASP classic is built up by Jscript and it only interpreted the Script line by line
when the page is requested. Moreover, ASP.net compilation is totally different with ASP classic.
ASP.net is automatically compiling all the code while the code is first time executed. The
compiled code will store inside .NET classes within assembly. .NET classes are including the
server-side coding and HTML code. So, when ASP.NET page is executed for first time, the
compiled code will store inside the .NET classes. Next time will render the ASP.net page by
execute the compiled code that has created. The performance for ASP.net will be increased
because there are no longer like the ASP classic has the difference between the compiled code
and the coding within the server-side languages within asp web page.
ASP.net performance is faster due to the compiled code but ASP classic is using the scripting
languages like VBScript. VBScript is representing to machine code and did not require any
additional parsing. That is why web developer is preferred to use ASP.net instead of using ASP
classic.
On the other hand, the difference between ASP.net and ASP classic is the scalability factor. For
ASP classic, the components inside the web pages are not easy to update, replace and maintain
it. If want to update particular component, IIS is required to shut down then only can
successfully replace or update the component. After done all the modification, IIS need to
restart once.( Neel Sus. 2009).
For ASP.net, it was different with ASP classic which it is scalable and easy to do modification on
the web pages. The term of ‘Xcopy’ command is used to build an efficiency ASP.net web
application page. The ‘Xcopy’ term is to copy a file to another location. It is allow to do the
modification without need of restart of web server. The web developer can do the changes on
the web application and no web server restart is required to take effect. It will direct take effect
once the web application is requested.(Bean Software. 2002).
ASP.NET Fundamentals
ASP.NET Fundamentals covers basic topics of ASP.NET Framework such as Session, Cookie,
HTTP Handler, HTTP Module, Forms Authentication, Caching, Exception Handling, ASP.NET
Request Processing etc.
1. What is ASP.NET?
ASP.NET is a framework developed by Microsoft to build dynamic web applications. There are
two programming models to develop web applications using ASP.NET.
ASP.NET Web Forms
ASP.NET MVC
Both programming models use ASP.NET on the top of that.
ASP.NET is also a part of Microsoft's .NET Framework. We can write ASP.NET Applications code
in any .NET Framework supported language i.e. C#, J#, F#, VB etc.
ASP.NET applications can only be hosted under IIS Server which is available on Window
Operating Systems only.
Microsoft has now moved it's further development from this traditional .NET Framework
(Windows only) to new .NET Core, which is Cross Platform (supporting Windows, MAC OS, and
Linux) framework to develop software applications i.e. Desktop, Web, Console, Mobile
Applications.
Sessions are basically server variables that are used to store information on Server.
Session in ASP.NET enables you to store information on server & access that stored information
on your sub-sequent web-requests.
HTTP is a stateless protocol, it means every web-request is a new web-request in itself. It does
not hold or preserve previous request data. So, Sessions provides us a way to identify the user
from on the subsequent web requests.
How to set a value in session in C#:
Session["Email"] = "[email protected]";
How to retrieve the stored value from the session:
string email = Convert.ToString(Session["Email"])
3. What is Cookie in ASP.NET?
An HTTP Cookie is a piece of data that is stored on the user's browser. Whenever you make a
web-request, all the cookies associated with the domain are sent with the web- request.
On the server, we can access those cookies & read values from them. Hence, cookies help us in
maintaining state by storing data on client's machine.
You can add a cookie in ASP.NET in following way:
Response.Cookies.Add(new HttpCookie("Email", "[email protected]"));
To read the cookie, you can use below syntax:
string email = Convert.ToString(Request.Cookies["Email"]);
4. What is State Management in ASP.NET? Explain various techniques available for State
Management in ASP.NET?
State Management is a technique in ASP.NET to maintain states. There are following ways in
ASP.NET to maintain states:
1. Server Side
2. Session
3. Application
4. Client Side
5. Cookies
6. Query String
7. View States
8. Hidden Fields
5. Difference between Response.Redirect() and Server.Transfer() ?
Response.Redirect
Response.Redirect() is the most common way of redirecting a user from one web-page to
another. For example, Whenever you write Response.Redirect("~/default.aspx") in the code,
server sends the response to browser with 302 status code. It also sends the location where the
browser needs to redirect the user in Location header in the response. So, whenever, the
browser receives 302 status code, it looks for Location header in the response and redirects the
user to that web page.
Server.Transfer
Server.Transfer() is the way of redirecting a user from the server. For example, if you write
Server.Transfer("~/default.aspx") in code, the server will redirect user to default.aspx page &
will display the response provided by default.aspx page.
Differences between Response.Redirect() and Server.Transfer()
In Response.Redirect(), it's browser's responsibility to redirect the user to a web-page while
in Server.Transfer() it is Server's responsibility.
In Response.Redirect(), URL changes to the new one while in Server.Transfer() URL doesn't
changes.
Server.Transfer() is faster than Response.Redirect().
Application Location
The asp.net application folder is contains list of specified folder that you can use of specific type
of files or content in an each folder. The root folder structure is as following
1. BIN
2. App_Code
3. App_GlobalResources
4. App_LocalResources
5. App_WebReferences
6. App_Data
7. App_Browsers
8. App_Themes
1. Bin Directory
It is contains all the precompiled .Net assemblies like DLLs that the purpose of application uses.
2. App_Code Directory
It is contains source code files like .cs or .vb that are dynamically compiled for use in your
application. These source code files are usually separate components or a data access library
3. App_GlobalResources Directory
It is contains to stores global resources that are accessible to every page.
4. App_LocalResources Directory
It is serves the same purpose as app_globalresources, exept these resources are accessible for
their dedicated page only
5. App_WebReferences Directory
It is stores reference to web services that the web application uses.
6. App_Data Directory
It is reserved for data storage and also mdf files, xml file and so on.
7. App_Browsers Directory
It is contains browser definitions stored in xml files. These xml files define the capabilities of
client side browsers for different rendering actions.
8. App_Themes Directory
It is contains collection of files like .skin and .css files that used to application look and feel
appearance.
ASP.Net Lifecycle
1) Application Start - The life cycle of an ASP.NET application starts when a request is made
by a user. This request is to the Web server for the ASP.Net Application. This happens
when the first user normally goes to the home page for the application for the first time.
During this time, there is a method called Application_start which is executed by the
web server. Usually, in this method, all global variables are set to their default values.
2) Object creation - The next stage is the creation of the HttpContext, HttpRequest &
HttpResponse by the web server. The HttpContext is just the container for the
HttpRequest and HttpResponse objects. The HttpRequest object contains information
about the current request, including cookies and browser information. The
HttpResponse object contains the response that is sent to the client.
3) HttpApplication creation - This object is created by the web server. It is this object that
is used to process each subsequent request sent to the application. For example, let's
assume we have 2 web applications. One is a shopping cart application, and the other is
a news website. For each application, we would have 2 HttpApplication objects created.
Any further requests to each website would be processed by each HttpApplication
respectively.
4) Dispose - This event is called before the application instance is destroyed. During this
time, one can use this method to manually release any unmanaged resources.
5) Application End - This is the final part of the application. In this part, the application is
finally unloaded from memory.
Directives
A directive controls how the page is compiled. It is marked by the tags, <%@ and %>. It can
appear anywhere in a page. But, normally it is placed at the top of a page. The main types of
directives are:
• Page
• Import
A Page directive is used to specify the default programming language for a page.
<%@ Page Language="C#" %>
OR
<%@ Language="C#" %>
Some namespaces are imported into an ASP.NET page by default. If you wish to use a class that
is not contained in the default namespaces, you must import its namespace.
<%@ Import Namespace="System.Data.SqlClient" %>
Code Declaration Blocks
A code declaration block contains all the application logic for a page. It also includes
declarations of global variables, and functions. It must be written within the script runat=
"server" tag.
The <script> tag has two optional parameters:
• Language: You can specify the programming language to be used within the <script> tag.
Otherwise, the language specified in the Page directive is used.
• SRC: You can specify an external file that contains the code block.
There is no difference in output between writing the code on the same page and including an
external script file.
ASP.NET Controls
ASP.NET controls can be mixed with text and static HTML in a page. All controls must appear
within a <form runat= "server"> tag. Some controls such as <span runat= "server"> and the
Label control can appear outside this tag. You can have only one form per page in ASP.NET.
Code Render Blocks
If you wish to execute code within HTML, you can include the code within code render blocks.
There are two types of code render blocks:
• Inline Code: It executes a statement or series of statements. It is marked by the characters <%
and %>.
• Inline Expressions: They display the value of a variable or method. They can be considered as
shorthand notation for the Response.Write method. They are marked by the characters <%=
and %>.
Server-Side Comments
You can add comments in server-side code using the characters <%-- and --%>. The main use of
these comment blocks is to add documentation to a page.
Server-Side Include Directives
You can include a file in an ASP.NET page by using a server-side include directive. It is
executed before any of the code in the page. If the file is in the same directory or in a
sub-directory of the page including the file, this directive is written as:
<!-- #INCLUDE file="includedfile.aspx" -->
You can also specify the virtual path of the file. To include a file located in the directory
MyAspx under the wwwroot directory, you will write the directive as:
<!-- #INCLUDE virtual="/MyAspx/includedfile.aspx" -->
Attributes Description
AutoEventWireup The Boolean value that enables or disables page events that are being
automatically bound to methods; for example, Page_Load.
Buffer The Boolean value that enables or disables HTTP response buffering.
ClientTarget The browser for which the server controls should render content.
Debug The Boolean value that enables or disables compilation with debug
symbols.
EnableViewState The Boolean value that enables or disables view state across page
requests.
TraceMode It indicates how trace messages are displayed, and sorted by time or
category.
Transaction It indicates if transactions are supported.
ValidateRequest The Boolean value that indicates whether all input data is validated
against a hardcoded list of values.
Application Folder
The asp.net application folder is contains list of specified folder that you can use of specific type
of files or content in an each folder. The root folder structure is as following
1. BIN
2. App_Code
3. App_GlobalResources
4. App_LocalResources
5. App_WebReferences
6. App_Data
7. App_Browsers
8. App_Themes
1. Bin Directory
It is contains all the precompiled .Net assemblies like DLLs that the purpose of application uses.
2. App_Code Directory
It is contains source code files like .cs or .vb that are dynamically compiled for use in your
application. These source code files are usually separate components or a data access library
3. App_GlobalResources Directory
It is contains to stores global resources that are accessible to every page.
4. App_LocalResources Directory
It is serves the same purpose as app_globalresources, exept these resources are accessible for
their dedicated page only
5. App_WebReferences Directory
It is stores reference to web services that the web application uses.
6. App_Data Directory
It is reserved for data storage and also mdf files, xml file and so on.
7. App_Browsers Directory
It is contains browser definitions stored in xml files. These xml files define the capabilities of
client side browsers for different rendering actions.
8. App_Themes Directory
It is contains collection of files like .skin and .css files that used to application look and feel
appearance.