Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

Migration from ASP to ASP.NET by uqg17706

VIEWS: 130 PAGES: 43

									Migration from ASP to

Anand M. Hegde
Developer Support Engineer
Microsoft Developer Support
Microsoft Corporation
   Why should you migrate?
   Introduction to Microsoft® ASP.NET
   Key changes from ASP to ASP.NET
   Migrating from ASP to ASP.NET
   Migrating applications that use COM
   Migrating applications that use databases
   Migration best practices
   ASP to ASP.NET compatibility FAQ
   Resources for ASP.NET and migration         2
Why Should You Migrate?
   Increased scalability and reliability
   Minimum 2X to 3X performance gain
   Built-in cross-browser compatibility
   Rich server-side controls, Microsoft
    Visual Studio® .NET designer support, and
    configuration options
   X-copy deployment of pages and components
   Better debugger; tracing options
   Content-code separation
   Take advantage of new caching features
   Enhanced state-management features
   ASP and ASP.NET can run side-by-side if required
   Many new features                                  3
Before You Migrate
   Get a good understanding of ASP.NET
   Know the changes from ASP to ASP.NET
   Understand that migration requires code
   Although ASP.NET has excellent backward
    compatibility, migration may not be as easy
    as it seems in many cases

Introduction to ASP.NET
   ASP.NET is:
       A new programming framework for Web
       An overhaul of ASP
       A part of Microsoft .NET
       Compiled and event driven programming model
   It permits you to:
       Rapidly develop powerful Web applications and
       Easily build, deploy, and run Web applications
        that can target any browser or device
   It requires:
       Microsoft Windows® 2000 or later for hosting and
        development                                        5
ASP.NET Architecture

ASP.NET Request Flow
                 Parse   ASPX      Generate       behind
                         engine                    class

              ASPX                      Gen’d
               file                     page
                         Instantiate    class
 Request                                 file

                         class     Instantiate,
                                  process, and
ASP.NET Page Life Cycle
   ASP.NET pages are event based
   Event flow in ASPX pages
       Page_Init: the page and controls are
       Page_Load: all the controls and page are
       Change events for controls are processed
       Click events for controls are processed
       Page_PreRender: page is about to render
       Page_Unload: page is unloaded from
ASP 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
         A true separation between code and content

         One File           Two files. (―code behind‖ model)

         Page.aspx           Page.aspx         Page.aspx.vb

             +                <Tags>             Code
ASP.NET Features
   Life made easy for developers
       Excellent backward compatibility with classic
       Visual Studio designer support, rich server
        controls, and base class library support
       Write code in the language of your choice
       Call Microsoft Win32® APIs directly
       Structured error handling
       Great debugging and tracing support

ASP.NET Features (2)
   Performance, scalability, and reliability
       Compiled code means speed
       Cache APIs to improve performance and
       Built-in support for WebFarms and WebGardens
       Nonstop availability and protection against
        deadlocks, memory leaks, and so on

ASP.NET Features (3)
   Easy deployment
       X-copy deployment
       Dynamic updates without interrupting the service
       No more registry! — use XML-based configuration
   New application models
       Develop mobile Internet applications with ease
       Built-in support to use XML WebServices
   More control with the new security model
   Flexible session state management
   Many other new features                                12
Core Object Changes
   Request object changes:
       Request(item), Request.QueryString(item), and
        Request.Form(item) now return a name value
           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 core objects now have many new
    properties and methods.
   There are some new objects available
       For example: cache, user and trace                           13
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 <% %>             14
Structural Changes (2)
   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 (3)
   No Render functions permited
     Change:
         <% MyRenderFunction
            Sub MyRenderFunction() %>
                <h1> Hi there! </h1>
         <%end sub%>
         <% Call MyRenderFunction()%>
         <script runat=“server” language=“vb”>
                  Response.Write(“Hi there!”)
Structural Changes (4)
   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
       Sample page directive:

        <%@ Page Language="VB" ContentType="text/xml" %>
       See the documents on new page directives

Application Configuration
   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
       For example: application protection level, session
        state                                                18
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
     SQLServer – session data stored in Microsoft
                     SQL Server™ (fast)
     Off          – disable session state
   Session state can be configured using
    <sessionState> section
   Can store COM components in session only in
   Can store managed components in any session state
    modes                                               19
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
       File authorization
       URL authorization
       Permit and deny users access to the application
Migrating VBScript to Visual
Basic .NET
   No VBScript in ASP.NET — it’s all Microsoft
    Visual Basic® .NET!
   Changing the file name extension to .aspx is the first
   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 (except for indexed
    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 (2)
   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
                 MyCount = InternalValue
             End Get
                 InternalValue = value
             End Set
       End Property
Migrating JScript to JScript .NET
   Start by changing the file name extension to .aspx
   Declare your variables explicitly
   Microsoft JScript® .NET language changes
       You can now pass variables by reference
       ―expando‖ modifier available to extend user-defined objects
       Can use COM components directly from JScript .NET
       Server Object’s methods are case sensitive
       The Arguments object is not available — use a parameter
        array instead
       Functions cannot be redefined
       For Large pages, move function/method code out of <% %>
        blocks to <Script runat=―server‖> blocks
Migrating Applications that Use
COM Components
   COM related changes:
       ASP.NET uses MTA instead of STA
       Pages with STA components may or may not perform well
       Early binding is preferred in ASP.NET
       Cannot use ASPCOMPAT with WebServices
   COM Interop
       Can use all your former COM components in ASP.NET
       Use ASPCOMPAT keyword if you plan to use existing STA
        components in ASP.NET
       Use ASPCOMPAT only when using STA objects or when
        your COM objects access ASP intrinsic objects
COM Objects Migration — FAQ
   What if the page contains both MTA and
       Use ASPCOMPAT
   What if I have a middle tier containing COM
       Use horizontal or vertical migration strategies
   What about the performance if I use existing
    COM objects?
       Very little overhead if the method does
        substantial tasks
       Significant overhead if the method does not do
        much                                              26
COM Objects Migration — FAQ (2)
   What about deploying COM objects used in
    ASPX pages?
       If you want to use Server.CreateObject, then there
        is no change
       If you use early binding then use the PIA (Primary
        Interop Assembly) for the COM component and
        make sure you deploy the PIA on the target server
   How can I use STA components from XML
       Register the component in COM+ and make sure
        you are running Windows 2000 SP2

Migrating Applications that Use
   Data access changes
       ADO (through Interop) can be used, but Microsoft
        does not recommend it
       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                                 28
Migrating Applications that Use
Databases (2)
   Strategies
       Rewrite ADO code in ADO.NET instead of
       Keep ADO code as a short term approach
       If you use ADO code in ASP pages, use Primary
        Interop Assembly for ADO on both the developer
        box and the server
       If you need read-only data, use a DataReader

Data Access Migration — FAQ
   What if my application has straight ADO code
    in ASP pages?
       Use ASPCOMPAT to use the code as it is (may be
       Rewrite the data access code to use ADO.NET
   What if my application has COM objects that
    use data access?
       Use the ASPCOMPAT attribute (if component
        uses STA)
   What if my database has no managed
       You can use OLEDB providers in ADO.NET
       If there are no OLEDB providers, use ODBC
        managed provider
Data Access migration — FAQ (2)
   What if I have a data access tier?
       Make these objects call Web Services or managed
       Later on, modify the presentation layer to use
        only .NET middle tier
   Do I have to package ADO Components
    during deployment?
       Make sure your server has MDAC 2.6 installed
       Make sure you also deploy the PIA for ADODB on
        the server

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
   In a multi-tier scenario, take the horizontal or
    vertical approach
       Horizontal – migrate the whole tier
                     (middle/presentation) at the same
       Vertical   – migrate some pages, some
                     components, at the same time
   Decide if you want to reuse existing COM
    components                                           32
General Migration Strategy (2)
   Decide if you want to keep current ADO code
    for a while
   Rename the file name extension from .asp to
   Make the language-specific changes first
   Make COM- and database-specific changes
   Test, test, test

Migration Best Practices
   General
       If the application is relatively small, consider
       If the application is very large, then plan carefully
        and migrate part by part
       If you only want to make a syntactic port, then
        consider only ASPX pages (that is, not using the
        ―code behind‖ model) and do not make
        unnecessary changes
       You do not have to port the whole site at the same
           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
       Write automated tools to do some tasks                   34
Migration Best Practices (2)
   Language related
       Strongly type all the variables
       If possible, convert all the On Error statements to
        try catch blocks
         Remember that they may not be as easy as
            they look
       Convert Include files into assemblies or user
        controls (.ascx)
       Use call keyword for function calls and use
        parenthesis for function and subroutine calls
       Identify default properties and replace them
       Always use Option Explicit
Migration Best Practices (3)
   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                                          36
Migration Best Practices (4)
   Testing related
       Update existing links to your Web site/pages
        because the file name extension is now .aspx
       Use a link checker to check any broken links,
        images, paths, and so on
       Test very well

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)
   Can they share session and application data?
       No – write custom code or use third-party
   What about Global.asa in ASP.NET?
       In ASP.NET, it is called as Global.asax

ASP to ASP.NET Compatibility —
FAQ (2)
   Can I use .NET components from ASP, and
    COM components from ASP.NET?
       Yes – use CCW to call managed components from
       Yes – use RCW to call COM components from
   What about the anonymous account in
       Remains the same
   What about the hosting process in ASP.NET?
       ASP.NET applications run under
       By default, ASP.NET worker process runs under
        an account called ASPNET
ASP to ASP.NET Compatibility —
FAQ (3)
   Do I need to write code for different
       No – ASP.NET produces HTML 3.2 compliant
   Can I still use ADO from ASP.NET?
       Yes – you can use ADO through Interop, but
        ADO.NET is preferred
   What about Include files?
       Can be used, but better to convert them to class
        libraries or user controls (.ascx) instead
   Can I call ASP pages from ASPX and vice
       Yes                                                40
ASP.NET Resources
   ASP.NET Quick Start Tutorials
   Authentication in ASP.NET Security
   ASP.NET Security
   Session State in ASP.NET
   ASP.NET Configuration

Migration Resources
   Migrating to ASP.NET: Key Considerations
   Migrating ASP Pages to ASP.NET
   Converting ASP to ASP.NET
   Upgrading to Microsoft .NET on GotDotNet
   Upgrading to .NET on MSDN
   Upgrading from JScript to JScript .NET
   Microsoft .NET/COM Migration and
   Q314775, ―INFO: Migrating Visual InterDev
    Design-Time Controls to ASP.NET‖
   .NET Migration Case Study                   42
Thank you for joining us for today’s Microsoft Support

For information about all upcoming Support WebCasts
and access to the archived content (streaming media
files, PowerPoint® slides, and transcripts), please visit:

We sincerely appreciate your feedback. Please send any
comments or suggestions regarding the Support
WebCasts to


To top