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
ASP.NET

Anand M. Hegde
Developer Support Engineer
Microsoft Developer Support
Microsoft Corporation
Overview
   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
    components
   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
    changes
   Although ASP.NET has excellent backward
    compatibility, migration may not be as easy
    as it seems in many cases



                                                  4
Introduction to ASP.NET
   ASP.NET is:
       A new programming framework for Web
        applications
       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
        services
       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




                       6
ASP.NET Request Flow
                                                   Code
                 Parse   ASPX      Generate       behind
                         engine                    class
                                                    file


              ASPX                      Gen’d
 Request
               file                     page
                         Instantiate    class
 Request                                 file


           Response
                         Page
           Response
                         class     Instantiate,
                                  process, and
                                     render
                                                           7
ASP.NET Page Life Cycle
   ASP.NET pages are event based
   Event flow in ASPX pages
       Page_Init: the page and controls are
        initialized
       Page_Load: all the controls and page are
        loaded
       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
        memory
                                                   8
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
        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
                                                               9
ASP.NET Features
   Life made easy for developers
       Excellent backward compatibility with classic
        ASP
       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


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




                                                       11
ASP.NET Features (3)
   Easy deployment
       X-copy deployment
       Dynamic updates without interrupting the service
       No more registry! — use XML-based configuration
        files
   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
        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 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 >


                                                              15
Structural Changes (3)
   No Render functions permited
     Change:
         <% MyRenderFunction
            Sub MyRenderFunction() %>
                <h1> Hi there! </h1>
         <%end sub%>
      To:
         <% Call MyRenderFunction()%>
         <script runat=“server” language=“vb”>
                  Response.Write(“Hi there!”)
         </script>
                                                 16
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
        page
       Sample page directive:

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



                                                               17
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                                                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
                     (faster)
     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
    InProc
   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
    resources:
       File authorization
       URL authorization
       Permit and deny users access to the application
                                                               20
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
    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

                                                                21
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))
                                                              22
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
             Get
                 MyCount = InternalValue
             End Get
             Set
                 InternalValue = value
             End Set
       End Property
                                                   23
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
                                                                      24
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
                                                                25
COM Objects Migration — FAQ
   What if the page contains both MTA and
    STA?
       Use ASPCOMPAT
   What if I have a middle tier containing COM
    objects?
       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
    WebServices?
       Register the component in COM+ and make sure
        you are running Windows 2000 SP2

                                                             27
Migrating Applications that Use
Databases
   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
        migrating
       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



                                                         29
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
        slower)
       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
    providers?
       You can use OLEDB providers in ADO.NET
       If there are no OLEDB providers, use ODBC
        managed provider
                                                         30
Data Access migration — FAQ (2)
   What if I have a data access tier?
       Make these objects call Web Services or managed
        components
       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



                                                          31
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                                           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
    .aspx
   Make the language-specific changes first
   Make COM- and database-specific changes
   Test, test, test




                                                  33
Migration Best Practices
   General
       If the application is relatively small, consider
        rewriting
       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
        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
       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
        appropriately
       Always use Option Explicit
                                                              35
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




                                                        37
ASP to ASP.NET Compatibility —
FAQ
   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
        component
   What about Global.asa in ASP.NET?
       In ASP.NET, it is called as Global.asax


                                                           38
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
        ASP
       Yes – use RCW to call COM components from
        ASP.NET
   What about the anonymous account in
    ASP.NET?
       Remains the same
   What about the hosting process in ASP.NET?
       ASP.NET applications run under
        ASPNET_WP.EXE
       By default, ASP.NET worker process runs under
        an account called ASPNET
                                                        39
ASP to ASP.NET Compatibility —
FAQ (3)
   Do I need to write code for different
    browsers?
       No – ASP.NET produces HTML 3.2 compliant
        output
   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
    versa?
       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
   http://www.gotdotnet.com
   http://www.asp.net
   http://www.ibuyspy.com

                                         41
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
    Interoperability
   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
WebCast.

For information about all upcoming Support WebCasts
and access to the archived content (streaming media
files, PowerPoint® slides, and transcripts), please visit:
http://support.microsoft.com/webcasts/

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

                                                             43

								
To top