You are on page 1of 31

What Makes .

NET
Different?

Scott Mitchell
Overview
The evolution of the Web.
Classic ASP overview its strengths and
weaknesses.
Time for something new: an examination of
Microsofts .NET Strategy.
ASP.NET to the Rescue!
Comparing and Contrasting ASP.NET and
classic ASP.
For more information
The Evolution of the Web
Dynamic Scripts Distributed, Compiled
Static Web Pages
Dynamic scripts allowed for Programs
Content was static. To
user interaction with a Web
alter the look and feel of a
site. Web content could be Web pages are actual,
Web page, a programmer
dynamically generated programs created using
had to physically alter the
based on a number of object-oriented
contents of the page itself.
variables, such as user programming techniques.
The static nature of the input. Allowed for the Web These programs are
Web at this time removed to serve as an application compiled instead of
any possibility of a user medium.
interpreted like the scripts
interacting with a Web site
or interaction among Web
Development was anything of the past.
but easy. The scripting
sites. A focus on Inter-Web
nature of development led
Performance was great to poor programming server communication
and development easy, practices and messy code. allows developers to build
but the Web lacked any Also, interaction among Web truly distributed
real usability. sites was possible, but applications on the Web.
limited and difficult.
Classic ASP - Strengths
Low cost of entry
Quick and easy to learn for experienced
developers and new developers alike.
Can create very useful Web applications in
a relatively short amount of time.
An active ASP community
Many, many great classic ASP books, Web
sites, training classes, and conferences.
Classic ASP - Weaknesses
Script-based technology used, leading to
poorer performing, less readable code than a
compiled counterpart.
Encouraged developers to shamelessly
intermix code (script) and content (HTML).
Difficult to debug.
Lacked modern programming features, such
as trycatch exception handling, true object-
orientation, etc.)
Fixing Classic ASP
ASP.NET, as well shortly see, fixes all of
these problems inherent in classic ASP!

Before we look at ASP.NET, specifically,


lets first turn our attention to
Microsofts .NET Strategy.
Ready or .NET, here it comes!
In July 2000, Microsoft announced their .NET
Vision at their Professional Developer
Conference (PDC).
The main components of .NET include:
A runtime system (the Common Language
Runtime, or CLR)
A large set of classes that serve as an API for
programs run through the CLR (commonly
referred to as the .NET Framework classes, or the
.NET SDK).
New programming languages.
The CLR
Whenever a .NET program is executed, it is
fed into the CLR, which executes the
program.
The code expected by the CLR needs to be in
a special intermediate language (MSIL,
Microsoft Intermediate Language).
So, compilers like VB.NET turn source code
into this MSIL. This MSIL code is like a high-
level, architecture independent assembly
language.
The CLR (continued)

When the CLR first runs a .NET


program, it must convert this abstract
high-level assembly language into
platform-specific code (referred to as
Just-In-Time (JIT) compilation).
This JITed copy can then be run by the
CLR each time the program needs to be
run.
The CLR (Continued)

VB.NET VB.NET Intermediate


Source Code
Compiler
Code

JITed

Your
application CLR
running!!!
The .NET Framework
The .NET Framework contains a plethora of
developer libraries that insulates the OS from
the developer.
These libraries are broken down into
hundreds of classes grouped in logical
namespaces, where each namespace
separates a different set of classes.
The .NET Framework is similar in concept to
the Win32 API, except the .NET Framework is
OO-based and sensibly arranged with helpful
documentation.
The .NET Framework (Continued)

ASP.NET and the inherent server controls are


classes in the .NET Framework. The
System.Web namespace encapsulates the
classes used by ASP.NET.
This means that you can access and utilize .NET
classes from within an ASP.NET page, meaning
through an ASP.NET Web page you can do:

File Uploads Image manipulations


On the fly (de|en)cryption
Systems-level activities (Event log, perf. mon., etc.)
New Programming Languages
To create .NET programs, you need to
use a .NET programming language (one
that compiles to MSIL and uses the
.NET Framework classes). Such
languages include:
VB.NET C#
JScript.NET MS C++ .NET
Perl.NET COBOL.NET
Visual Basic .NET
VB.NET introduces many new modern
concepts into VB:
Try Catch exception handling
True OOP
Short-circuit Boolean operators, variable
initialization, standard array base (0), etc.
VB.NET has a handful of breaking changes:
No more default properties
Set/Let support dropped
Subs require parenthesized parameters
Example VB.NET Code
'Create an ArrayList
Dim myArrayList as New ArrayList()
myArrayList.Add("ASP.NET")
myArrayList.Add("is")
myArrayList.Add("cool!")
Response.Write(GetRandomWord(myArrayList))

Function GetRandomWord(myAL as ArrayList)


Dim rndNumber as New Random()
Return myAL(rndNumber.Next(myAL.Count))
End Function
C#
Microsofts newest language offering.
Similar to Java in syntax and semantics:
Case sensitive
Statements delimited by semicolons
Blocks delimited by curly braces
Like every .NET language, very OO.
Example C# Code
// Create an ArrayList
ArrayList myArrayList = new ArrayList();
myArrayList.Add("ASP.NET");
myArrayList.Add("is");
myArrayList.Add("cool!");
Response.Write(GetRandomWord(myArrayList));

string GetRandomWord(ArrayList myAL)


{
Random rndNumber = new Random();
return myAL[rndNumber.Next(myAL.Count)];
}
What Language to Use?
VB.NET and C# both rely on the classes in
the .NET Framework to accomplish their
tasks.
Therefore, essentially anything you can do
with C#, you can do with VB.NET.
Programs written in C# and VB.NET are
relatively equal in performance.
Therefore, choose the programming language
that you and your team knows best!
Language Interoperability
Realize that every data type (int, string,
object, etc.) is defined as a class in the .NET
Framework.
That means an int in C# and an Integer in
VB.NET are the same thing an instance of
the Int32 class in the .NET Framework.
Since all .NET languages:
Compile to standard MSIL
Use the same data type definitions
components written in one language can be
used in another.
ASP.NET to the Rescue!
ASP.NET solves for many of the
disadvantages in classic ASP.
ASP.NET Web pages are compiled .NET
programs created by modern .NET
programming languages (VB.NET, C#,
JScript.NET, Perl.NET, etc.)
ASP.NET provides excellent debugging options
and opportunities, especially through tools
like Visual Studio .NET
ASP.NET to the Rescue! (Continued)

ASP.NET encourages separation of code


and content (HTML) in many ways:
The use of Code-behind pages which
physically separate the code from the
content.
Use of server controls, which provide VB-
like control functionality through a Web
page. (Johns talk next will address server
controls in great detail!)
Examining ASP.NET
ASP.NET is comprised of two major areas: ASP.NET
Web pages and ASP.NET Web services.
ASP.NET Web pages are akin to classic ASP pages
Web surfers visit them through a browser and
are returned valid HTML.
ASP.NET Web services provide for inter-Web server
communications. This allows an ASP.NET Web
page (or a stand-alone application) to access a
remote program to obtain information. (More on
this topic in tomorrows talk on Web services.)
Examining ASP.NET (Continued)

ASP.NET Web pages and Web services are


compiled programs. So when a user visits
one of your ASP.NET Web pages, an actual
program is being executed the ASP.NET
Web page.
These Web pages and Web services are
compiled on-demand, meaning that when a
Web page or Web service is first visited, it is
compiled. From then on, a cached version
(using disk-based caching) of the
intermediate code is referenced.
Comparing ASP.NET and ASP
Classic ASP ASP.NET
ASP pages output standard ASP.NET contains Web
HTML code, thereby not controls that return HTML
requiring any specific browser. 3.2-compliant HTML.

Could use ADO to access Can access databases via


database information. ADO.NET.

Developers could create ASP.NET development is even


ASP pages quickly and quicker and easier than classic
ASP and utilizes VB.NET, which is
easily using VBScript very similar to VBScript.
Contrasting ASP.NET and ASP
Classic ASP ASP.NET
Uses scripting languages Uses compiled, .NET-
(VBScript / JScript/PerlScript) compatible language (VB.NET
/ C# / JScript.NET, etc.)
Web pages contain .asp Web pages contain .aspx
extension extension.

HTML and server-side Server-side script placed in


script intermixed. distinct SCRIPT blocks or
even separate source files.
Getting Started with ASP.NET
Need to install the .NET Framework
Only runs on Windows 2000 and Windows XP Pro
(requires that IIS 5.0+ be installed).
The .NET Framework is freely available to
download from http://www.asp.net/
Once the .NET Framework has been installed
you can create ASP.NET pages simply by
creating a file (using your favorite editor
(Notepad / Visual Studio, etc.) with a .aspx
extension in a Web directory (I.e.,
C:\InetPub\wwwroot\).
The Good News
ASP.NET and Classic ASP can run side-by-side
on a Web server. That is, you can have
ASP.NET Web pages and classic ASP pages
running on your Web site.
One of .NETs goals is to provide side-by-side
functionality, meaning you should be able to
run ASP.NET v2.0 and v1.0 on the same Web
server at the same time (whenever ASP.NET
v2.0 comes out, that is!).
Getting Started with ASP.NET
(Some Simple ASP.NET Web Pages Examples)

ASP.NET Web Pages can be created to look


just like classic ASP pages. Show
SimpleASP.NET.demo.aspx.
Note that when we run this demo, there is a
slight delay. The .NET Framework is actually
running an instance of the VB.NET compiler!
This delay only occurs when the page is
loaded for the first time after it is created or a
change to the source code has occurred.
Also note that ASP.NET Web pages output
regular HTML, just like classic ASP pages.
Getting Started with ASP.NET
(Some Simple ASP.NET Web Pages Examples)

ASP.NET Web pages are actual, OOP programs,


consisting of a class derived from the Page class
in the .NET Framework.
ASP.NET pages can be coded to handle the Page
class events (the most commonly used Page class
event handler youll create is for the Load event,
which fires when an ASP.NET page is visited).
ASP.NET pages ideally will contain server-side
SCRIPT blocks instead of in-line (<% %>)
script.
Show ProperASP.NET.demo.aspx
Online Resources
There are a plethora of .NET Web sites:
http://aspnet.4GuysFromRolla.com
http://www.asp101.com
http://www.15Seconds.com
http://www.asp.net
http://www.aspnextgen.com
http://www.aspalliance.com
There are many newsgroups and listservs and
online forums as well:
http://www.aspfriends.com
http://www.aspmessageboard.com
Questions???

Now would be a great


time to ask questions!

You might also like