Professional Documents
Culture Documents
NET
Migration
Nick Grattan
Technical Director, Software Paths Limited
MSDN Regional Director, Ireland
www.softwarepaths.com
www.microsoft.com/rd
Overview
Why migrate?
Why not to migrate?
Changes from ASP to ASP.NET
Migration
VBScript to VB.NET
ADO to ADO.NET
Strategy
Best Practice
Why migrate?
• Doculabs Nile Benchmark
Test.asp
<%
myobj=Server.CreateObject(“blah”)
%>
<a href=<%=myobj.DoSomething()%>/>
ASP
Serial Processing/Pull technology
No easy separation of code/content
Calls out to COM components
Intrinsic objects
Written using VBScript or JScript
Inherently typeless
Hard to debug
ASP.NET
ASP.NET
Test.aspx
<codebehind=“myclass.cs”/>
<html>
<asp:mycontrol id=“mycontrol1”>
</html>
myclass.cs
public page_load(){
mycontrol1.text =“Hello”;
}
ASP.NET
Event based/Push model
Calls to/from .net classes
Intrinsic objects
Inherently typed
VB, C#
Easier to debug
ASP.NET Programming Models
Two types of programming models exist
ASPX page only: contains HTML, control tags,
and code
Code behind model: ASPX file contains HTML and
control tags, and a “code behind” file contains
code
A true separation between code and content
<Tags>
+ <Tags> Code
Code
Intrinsic Object Changes
Request object changes:
Request(item), Request.QueryString(item), and
Request.Form(item) now return a name value
collection
In classic ASP, they return an array of strings
Use Response.Write with caution
It will output results at the top of the page before
the <HTML> tag
Instead:
Use server controls (placeholder)
Use <% %> tags if you want the output to appear in the right
place
Each of the Intrinsic objects now have many
new properties and methods
There are some new objects available
For example: cache, user and trace
Structural Changes
One page – one language
No mixing of languages in single page
A page can have only one server-side Form
tag and it must submit to the same page
An ASPX page may contain:
Directives: <%@ Directive %>
Server controls: <tag runat=server>
Code blocks: <script runat=server>
Data binding expressions: <%# %>
Server-side comments: <%-- --%>
Server-side includes: <!-- #include -->
Render code: <%= %> and <% %>
Structural Changes Cont’d
Code block–related changes
You cannot declare functions inside <% %> tags
Declare all your functions and variables inside
the server-side <SCRIPT> blocks
<Script runat=“server” language=“vb”>
dim gVar as String ‘Page level variable
private sub MySubRoutine()
Label1.Text = gVar
End Sub
</Script >
Structural Changes Cont’d
No Render functions permitted
Change:
<% MyRenderFunction
Sub MyRenderFunction() %>
<h1> Hi there! </h1>
<%end sub%>
To:
<% Call MyRenderFunction()%>
<script runat=“server” language=“vb”>
Response.Write(“Hi there!”)
</script>
Structural Changes Cont’d
New page directives
In ASP, directives had to be at the top of the
page, but you do not have to do this anymore
You can now have multiple directives on the
same page
Sample page directive:
<%@ Page Language="VB" ContentType="text/xml" %>
ASP to ASP.NET Compatibility
How can ASP and ASP.NET co-exist?
Because they have different file name
extensions
(.asp and .aspx)
Because they have different application
settings (registry and config files)
What about Global.asa in ASP.NET?
In ASP.NET, it is called as Global.asax
Demo – ASP and ASP.NET
Coexisting
Application Configuration Changes
ASP.NET application settings are stored in
XML configuration files
Types of configuration files
Machine.config
Contains machine-wide settings
Web.Config
Contains project/application-wide settings
Easy programmatic access to the data in
these files
Some of the settings in the IIS snap-in are
ignored
For example: application protection level, session
state
Session Management Changes
New session state storage mechanisms
InProc – session data stored on local
computer (fastest)
StateServer – session data stored in a state
service that can be located anywhere; ideal for
WebFarms (faster)
SQLServer – session data stored in
SQL Server (fast)
Off – disable session state
Session state can be configured using
<sessionState> section in Web.Config
Can store COM components in session only in InProc
Can store managed components in any session state
modes
Sharing Session State
Session state cannot be directly shared
between ASP and ASP.NET pages
Session object is different
Event in different processes
Need to decide what state needs to be shared
Often only a small subset of entire session state
Share by:
Writing to a common file
Using a database table
Etc.
Demo – Session State
Security Related Changes
The IIS part of the security remains same
New robust and flexible security model is based on
the security sections in the configuration files
New authentication modes
Windows: uses Windows Authentication
Forms: uses cookie-based custom logon forms
Passport: uses the Microsoft .NET Passport Service
None: no authentication
Authorization modes permit you to control access to
resources:
File authorization
URL authorization
Permit and deny users access to the application
Migrating VBScript to VB .NET
No VBScript in ASP.NET — it’s all VB.NET!
Changing the file name extension to .aspx is the first
step
Visual Basic language changes
Option Explicit is now the default
No more “variant” type — use type “Object”
Method and function calls with parameters now require
parenthesis, so change:
<% Response.Write “Hi” %>
to <% Response.Write (“Hi”) %>
By default, arguments are passed by value
Arrays are now zero based
Visual Basic Language Changes
Let and Set are not supported, so change:
Set MyObj1 = MyObj2
to MyObj1 = MyObj2
No more default properties, so change:
MyString as string = Textbox1
to MyString as string = Textbox.Text
Integer data type is now 32 bits and a Long data type
is 64 bits
Use structured error handling (try catch block)
instead of On Error (On Error still works)
Must cast data types explicitly:
Response.Write (“Count=“ & CStr(MyCount))
or Response.Write(“Count=“ & CType(MyCount, String))
Visual Basic Language Changes Cont’d
Must have spaces around “&” while doing
string concatenation, so change:
x = str1&str2
to x = str1 & str2
Property Get, Property Set, and Property Let
are not supported anymore, so instead use:
Public Property MyCount as Integer
Get
MyCount = InternalValue
End Get
Set
InternalValue = value
End Set
End Property
Migrating Applications that Use
Databases
Data access changes
ADO (through Interop) can be used, but not
recommend it
Try and avoid looping round recordsets
Use ADO.NET and bind to server controls
ADO and ADO.NET are quite different
ADO.NET is not exactly backward compatible
Three main objects in ADO.NET: DataSet, DataReader,
and DataAdapter
Two built-in managed data providers: SQLClient and
OLEDB
Built-in designer support for ADO.NET objects in
Visual Studio .NET
Migrating Applications that Use
Databases Cont’d
Strategies
Rewrite ADO code in ADO.NET instead of
migrating
Keep ADO code as a short term approach
If you need read-only data, use a
DataReader
Demo – Migrating ADO
Code
Ideal application for Migration
COM objects
Two stage migration
Minimal script
Especially client
Written to ASP best practice
Demo – Reusing COM
Components
Before You Migrate
info@SoftwarePaths.com
www.SoftwarePaths.com
Join us for Microsoft’s premier European
technical education conference
www.microsoft.com/europe/teched/
MS Press
Essential Resources for Developers
www.microsoft.com/mspress
Choose from Windows 2000, SQL Server 2000, Exchange 2000, Office
2000, .NET Framework, C#, VB.NET, ASP.NET, and XML
MSDN
Essential Resources for Developers
Subscription Library, Professional, Universal
Services Delivered via CD-ROM, DVD, Web