Unit 5 - ASP.NET Applications
Unit 5 - ASP.NET Applications
NET Applications
5.0 Objectives
5.1 Introduction
5.2 ASP.NET File Types
5.3 The Application/ Bin Directory
5.4 Code-Behinds in ASP .NET
5.5 The Global.asax
5.6 ASP .NET Configuration
5.7 Summary
5.8 Check your Progress - Answers
5.9 Questions for Self – Study
5.10 Suggested readings
5.0 OBJECTIVES
5.1 INTRODUCTION
Web site applications can contain a number of file types, some supported and
managed by ASP.NET, and others supported and managed by the IIS server. Most of
the ASP.NET file types can be automatically generated using the Add New Item menu
item in Visual Web Developer.
5.2 ASP.NET FILE TYPES
File types are mapped to applications using application mappings. For
example, if you use double-click a .txt file in Windows Explorer, Notepad will probably
open, because in Windows, .txt file types are mapped by default to Notepad.exe. In
Web applications, file types are mapped to application extensions in IIS.
Application root or a
.ascx A Web user control file that
subdirectory.
ASP.NET Applications / 83
defines a custom, reusable
control.
Application root or a
.cd A class diagram file.
subdirectory.
Source : http://msdn.microsoft.com/en-IN/library/2wawkw1c(v=vs.80).aspx
ASP.NET Applications / 85
Application root or a An Internet Database Connector file mapped to
.idc
subdirectory. httpodbc.dll.
.shtm,
Application root or a
.shtml, Mapped to ssinc.dll.
subdirectory.
.stm
IIS serves static files only if their file-name extensions are registered in the MIME types
list. This list is stored in the MimeMap IIS metabase property for an application. If a file
type is mapped to an application extension, it does not need to be included in the
MIME types list unless you want the file to be treated like a static file. Typically,
ASP.NET source code file types should not be in the MIME types list because that
might allow browsers to view the source code.
The following table lists only a few of the registered file types.
File
Location Description
type
ASP .NET / 86
automatically picked up by the runtime. When a change is detected, ASP.NET allows
currently executing requests to complete, and directs all new incoming requests to the
application that uses the new component or components.
5.4 CODE BEHINDS IN ASP.NET
Even though ASP.NET is the next version of ASP, it is more than just a next
version. ASP.NET is completely re-designed from the ground up and it provides a neat
object oriented programming model. An ASP.NET page is an object derived from the
.NET Page class. We all know that ASP.NET provides several new features and one
of the important features is the separation of code and content.
In today's ASP application, we have a mix of HTML and Scripts making the
code difficult to read, debug and maintain. ASP.NET relieves us from this problem by
promoting the separation of code and content. That is, the user interface and the user
interface programming logic need not necessarily be written in a single page. There
are two ways in which you can separate the code and content:
1) By using Code-behind files that are pre-compiled modules written in any of the
Microsoft .NET runtime compliant languages.
2.) By developing the frequently used page logic in to separate files called Pagelets
(also known as page controls) and by using them several times in your ASP.NET
pages.
As the title of the article indicates, I will explain the first mechanism that is
used to neatly encapsulate the UI functionality in to a separate pre-compiled module.
You will typically follow the steps below to develop an ASP.NET page that uses code-
behind pages:
1) Create the User Interface using the HTML and/or Web controls and store them
in an ASP.NET page with extension ".aspx".
2) Create the code-behind file using the .NET runtime classes that mimic the entire
ASP.NET page with the member variables that correspond to the HTML and/or
Web controls used in the ASP.NET page. The extension of code behind files will
vary depending on the language you use. Typical extensions will be .cs for C#,
.vb for VB7 and .js for JScript .NET
Now, we know that there are two separate files: one for the UI and the other
for the UI logic. But, how do we relate these two files so that the ASP.NET page
compiler will locate the code-behind file for the ASP.NET page. The glue between
these two files is provided through the Page Directives, which are used to specify
optional settings at the page level.
<HTML><BODY>
<form action="CodeBehind.aspx" method=post runat="server">
<h5>Sign-In Form</h5>
Login: <asp:TextBox id=txtLogin Width=200 Runat=server />
<asp:RequiredFieldValidator ControlToValidate="txtLogin"
Display="Static" Font-Name="verdana,arial,sans-serif"
Font-Size="9pt" ErrorMessage="You must enter a Login."
runat="server" ID="RFVLogin" />
ASP.NET Applications / 87
<P>
Password: <asp:TextBox id=txtPassword Width=200 Runat=server
TextMode="Password" />
<asp:RequiredFieldValidator ControlToValidate="txtPassword"
Display="Static" Font-Name="verdana,arial,sans-serif"
Font-Size="9pt" ErrorMessage="You must enter a password."
runat=server ID="RFVPassword"> </asp:RequiredFieldValidator>
<P>
<asp:Button id=btnSignIn Runat="server"
Text="Sign In" onClick="btnSignIn_Click" />
</FORM>
</body></html>
The first line of the ASP.NET page is the page directive that specifies the name of the
code behind file and the actual class name inside that file. In our example, the file
name is CodeBehind.cs and the class name is ASPPlus.CodeBehind.
The namespace that I used for this code behind page is ASPPlus. Namespaces
provide the naming scope for the classes and is very convenient way to represent
hierarchy of classes. The rest of the code consists of HTML tags and Web Control
declaration tags. The main thing to note down in this page is the ID properties of the
controls. I will explain the importance of these IDs when we discuss the code-behind
file.
Configuration information is stored in XML-based text files. You can use any
standard text editor or XML parser to create and edit ASP.NET configuration
files.
ASP .NET / 90
Check your progress 5.5-5.6
Answer the following questions in 1-2 sentences.
a) What is Global.asax?
………………………………………………………………………………………………
………………………………………………………………………………………………
b) Explain asp.net configuration.
………………………………………………………………………………………………
………………………………………………………………………………………………
5.7 SUMMARY
Web site applications can contain a number of file types, some supported and
managed by ASP.NET, and others supported and managed by the IIS server.
Most of the ASP.NET file types can be automatically generated using the Add
New Item menu item in Visual Web Developer.
In asp.net directory is always named /bin, and is located immediately under the
root directory for the application (a virtual directory defined by Internet
Information Services (IIS)).
The Global.asax file (also known as the ASP.NET application file) is an optional
file that is located in the application's root directory and is the ASP.NET
counterpart of the Global.asax of ASP.
5.8 CHECK YOUR PROGRESS – ANSWERS
5.2
1. .asax, .ascx
2. If the file name, extensions are register in the MIME File types.
5.3-5.4
1. To solve the traditional problem of com object, Microsoft create a well known \
bin directory to store application file at run time.
2. Meaning of it means that your page designee is distinct from your coding.
5.5 – 5.6
1. It is a file used to declare and handle application / session level events, object
for ASP .NET website running on IIS web server.
2. ASP .NET configuration means now your website will work in term of – Role,
Authentication, and Authorization. These all are customizable and we find them
in web.config file>system.web.
ASP .NET configuration gives us easy way to manage our web page and other
type of administration. We can do it by code also.
ASP.NET Applications / 91