You are on page 1of 43

ASP to ASP.

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

Ref. Doc: http://www.gotdotnet.com/team/compare/_Toc528311245


Why migrate? Cont’d
 Increased scalability and performance
 Compiled code
 Rich server controls
 XCopy deployment
 Debugging that works
 Content/Code separation
 Enhanced caching and session state
 Choice of strongly typed languages
 Plus many more
Why not to migrate?
 Migration vs. Rewrite
 ASP.NET is very different from ASP
 Not just a superset
 Backwards compatibility is supported
 Do you have a lot of client side script?
 Do you have a lot of server side script?
 Is application near end of lifecycle?
 Is it worth the effort?
ASP

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

One File Two files. (“code behind” model)

Page.aspx Page.aspx Page.aspx.vb

<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

 Get a good understanding of ASP.NET


 Know the changes from ASP to ASP.NET
 Understand that migration requires code
changes
 Although ASP.NET has excellent backward
compatibility, migration may not be as easy as
it seems in many cases
General Migration Strategy
 Identify the parts of the application that you have to
migrate
 Plan very carefully and try to have minimal impact on
the existing application during the migration
 In a multi-tier scenario, take the horizontal or vertical
approach
 Horizontal
 migrate the whole tier (middle/presentation) at the same time
 Vertical
 migrate some pages, some components, at the same time
 Decide if you want to reuse existing COM
components
General Migration Strategy Cont’d
 Decide if you want to keep ADO code
 Rename the file name extension from
.asp to .aspx
 Make the language-specific changes first
 Make COM- and database-specific
changes
 Test, test, test
Migration Best Practices
 If the application is relatively small, consider
rewriting
 If you only want to make a syntactic port,
then consider only ASPX pages
 You do not have to port the whole site at the
same time
 Consider migrating the slow/critical parts
 Remember, you can run ASP and ASP.NET side-by-side
 Try to migrate the read-only pages first
Migration Best Practices Cont’d
 Language related
 Convert Include files into assemblies or user controls
(.ascx)
 Data access related
 If you have a data access tier, move it into .NET
 COM related
 Always use early binding
 Explicitly free resources from code
 Project management related
 Keep two code trees while migrating, and make sure to
update both of them while adding changes to the existing
Web site
 First try to modify the existing code as it is
 After you complete this, try to modify the application to use
the advantages provided by .NET
Conclusion
 No simple migration path
 Need to assess application
 Current application architecture
 Changes that need to be made
 Future Development of Web Site
 Need to understand ASP.NET to plan
migration
Software Paths Ltd
.NET Services
 Training Courses  Consulting
 .NET Overview (1 day)  Technology guidance
 ASP.NET (4 days)  Review of
 Web Services (3 days) applications
 C# Programming (3  .NET Architecture
days)  Web Services
 VB.NET Intro (3 days)
 Migrating from VB6 to
VB.NET (2 days)

info@SoftwarePaths.com
www.SoftwarePaths.com
Join us for Microsoft’s premier European
technical education conference

30 June – 4 July, Barcelona, Spain

The definitive Microsoft conference for designing,


Building and managing connected solutions

www.microsoft.com/europe/teched/
MS Press
Essential Resources for Developers

Find out other titles from MS Press books at

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

Online MSDN Online, MSDN Flash


Information

Training & MSDN Training, Tech-Ed, PDC,


Events Developer Days, MSDN/Onsite Events

Print MSDN Magazine


Publications MSDN News

Membership MSDN User Groups


Programs
Where Can I Get MSDN?
 Visit MSDN Online at
msdn.microsoft.com
 Register for the MSDN Flash Email
Newsletter at
msdn.microsoft.com/flash
 Become an MSDN CD Subscriber at
msdn.microsoft.com/subscriptions
 MSDN online seminars
msdn.microsoft.com/training/seminars
 Attend More MSDN Events
For More Information…
 MSDN Web site at
 msdn.microsoft.com
 msdn.microsoft.com/net
 Got Dot Net
 www.gotdotnet.com
 ASP.NET
 www.asp.net

You might also like