migrating from asp.net 1.1 to asp.net 2.0 scott guthrie web platform and tools team microsoft...

28
Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation [email protected]

Upload: lionel-mason

Post on 21-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Migrating from ASP.NET 1.1 to ASP.NET 2.0

Scott GuthrieWeb Platform and Tools TeamMicrosoft [email protected]

Page 2: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Agenda

• Migrating from ASP.NET 1.X to ASP.NET 2.0• Visual Studio 2003 to Visual Studio 2005

Conversion

Page 3: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Migrating from ASP.NET 1.X to ASP.NET 2.0

Page 4: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

ASP.NET 1.X to ASP.NET 2.0

• Goal: Easy to upgrade from V1.1 to V2.0– We have minimized breaking changes– No OS upgrade required

• Runs on Windows 2000 & IIS 5.0• Runs on Windows XP & IIS 5.1• Runs on Windows Server 2003 & IIS 6.0

• Please Let us know if you find issues with Beta2

Page 5: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

ASP.NET 1.X to ASP.NET 2.0

• ASP.NET 1.1 & 2.0 can be installed on same machine– Application versions run side-by-side under IIS– Version used identified by IIS vroot ISAPI script-mappings

• Installing v2.0 on v1.1 server preserves existing v1.1 application mappings– V1.1 applications do not automatically get updated to use V2.0– Administrator must manually update application using IIS Admin Tool

• Existing ASP.NET v1.1 applications should run fine using ASP.NET v2.0– But always test application prior to deployment to verify

Page 6: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Issue Tracker – V1.1Issue Tracker – V1.1 version running on top of ASP.NET 2.0

Page 7: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

ASP.NET 1.X to ASP.NET 2.0

• It is possible to upgrade parts of a site to ASP.NET V2.0 while leaving the rest of it to run under ASP.NET V1.1 – http://foo.mysite.com on V2.0 and http://www.mysite.com on V1.1– http://www.mysite.com on V2.0 and http://www.mysite.com/foo on

V1.1

• Forms Authentication can work across both ASP.NET versions – To enable in ASP.NET 2.0 you must explicitly set decryption

attribute in the machineKey section to 3DES• ASP.NET 2.0 encryption default of AES is not compatible with 1.1

• Tickets issued in 1.1 are then consumable by ASP.NET 2.0• Tickets issued by ASP.NET 2.0 are then consumable by 1.1 app

Page 8: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Sharing forms authentication tickets

Page 9: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

ASP.NET 1.X to ASP.NET 2.0

• New ASP.NET reserved directory names (App_)– New naming convention for protecting directories– Avoid naming directories with this prefix

• ASP.NET Reserved directories– /Bin – Reserved for assemblies. Same as 1.0 and 1.1– /App_Code – Reserved for code– /App_Data – Reserved for data storage (*.mdf, .xml, etc.)– /App_Themes – Reserved for theme files (.skin)– /App_WebServices – Reserved for .wsdl files– /App_Resouces – Reserved for local page resource files– /App_GlobalResources – Reserved for global resource files

Page 10: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

ASP.NET 1.X to ASP.NET 2.0

• XHTML compliance switch– XHTML compliant markup is now emitted by default – Good for standards compliance, but can break some UI

• <xhtml11Conformance enableLegacyRendering=“true” />

– Web.config file setting to use older HTML markup rendering– Set this to help with migration of existing sites– Recommend updating pages to be XHTML compliant long-

term

Page 11: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

ASP.NET 1.X to ASP.NET 2.0

• Other XHTML issues:– New pages created using VS2005 include a DOCTYPE

directive indicating XHTML 1.1 compliance

– IE will render page in browser differently if DOCTYPE present• Remove the DOCTYPE to get older html rendering

behavior

– In future you should update your HTML to be XHTML compliant

Page 12: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

ASP.NET 1.X to ASP.NET 2.0

• Well known client-side script files are now encapsulated as resources– .js files are now referenced like: WebResource.axd?

a=s&amp;r=WebUIValidation.js

– Hand-editing WebUIValidation.js file will no longer work

– Use the expanded client-side scripting support in ASP.NET 2.0 for enabling common client-scripting scenarios instead

Page 13: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

ASP.NET 1.X to ASP.NET 2.0

• Potential for naming collisions with existing source code– 2,000+ new classes in V2.0– Common name collisions: Membership, Roles, Profile, Theme

• Name collisions do not affect already compiled binaries– CLR automatically picks the correct type to use in this case– Name collisions will affect you if you re-compile your project source

• Recommend you identify collision candidates today– Use a fully qualified class name when referencing these types

• (e.g. MyProject.Membership instead of Membership)– Alternatively use an alternative class name to avoid future issues

Page 14: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Visual Studio 2003 to Visual Studio 2005 Conversion

Page 15: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Visual Studio Conversion

• VS 2005 makes significant changes to web projects– Provides much more flexibility for web scenarios

• Key Benefits:– No more project file required– Web projects no longer compiled into single DLL– Web projects can now be written in multiple languages– No need to re-compile project when making changes– Ability to update pages/code while using the debugger– Significantly cleaner and more robust code-behind model

Page 16: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Visual Studio Conversion

• VS 2005 converts existing VS 2003 projects on open– One way conversion (cannot open in VS 2003 afterwards)– Always enable backup option as part of upgrade wizard– ConversionReport.txt lists all changes as part of the upgrade

• Things to be aware of during conversion:– New directories may be created (App_Code, App_WebReferences)– Non-page related class files (.cs, .vb) will be moved to App_Code

dir– “Designer generated” sections are processed by the conversion

tool– Pages automatically updated to use new code-behind model

• Recommendations when running under source control:– Move project to new location on disk (out of source control)– Open project and run the conversion wizard– Check back into source control

Page 17: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Visual Studio Conversion

• New Code-Behind Model– Removes need for VS to generate/modify code in your code-behind– Control definition now handled using new partial class feature of V2

compilers– Still enables definition of custom base pages + control classes

• Syntax differences:– ASP.NET 1.1 page definition

• <%@ page codeBehind=“webform1.aspx.cs” inherits=“WebForm1” %>

– ASP.NET 1.1 code-behind class definition • public class WebForm1 : System.Web.UI.Page

– ASP.NET 2.0 page definition• <%@ page codeFile=“webform1.aspx.cs” inherits=“WebForm1” %>

– ASP.NET 2.0 code-behind class definition • public partial class WebForm1 : System.Web.UI.Page

Page 18: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

ASP.NET 2.0 Code-behind

Default.aspx

<%@ Page codefile=“default.aspx.cs” inherits=“Default”

public partial class Default : System.Web.UI.Page

Default.aspx.cs

File containing code behind

class definition

File containing code behind

class definition

Class that the page-gen inherits from

Class that the page-gen inherits from

Class is ‘partial’ and is combined to an auto-generated partial

class

Class is ‘partial’ and is combined to an auto-generated partial

class

Base class. Can be defined by user. The required ancestor base class is

System.Web.UI.Page

Base class. Can be defined by user. The required ancestor base class is

System.Web.UI.Page

Dynamic Compile

Auto-generated page class

MyClass

Auto-generated partial

Default

Partial class defined in codefile

Default System.Web.UI.Page

Page 19: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Issue Tracker – After running the conversion wizard

Page 20: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Visual Studio Conversion

• New dynamic compilation model implications:– Monolithic code-behind assembly is no longer used

• Instead, pages are compiled on-demand into separate assemblies

– Code-behind code that references classes defined within other code-behind files will fail

• Move these classes out of code-behind files into standalone .cs and .vb files (can use App_Code directory or separate assembly)

– Best practice to prepare for this with ASP.NET 1.1:• Move classes, enumerations and interfaces that are not

related to a page into standalone .vb or .cs files now• In addition to making migration easier it is a better coding

practice

Page 21: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Cross file class references

Page 22: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Visual Studio Conversion

• New dynamic compilation model implications:– Type casting dynamically loaded user controls

requires an explicit reference to the .ascx files• In 1.1, since all code lived in the same assembly, user

control type names were always available for type casting

– In 2.0, add <% @Reference VirtualPath=“ctl.ascx” %> page directive

• MyControl ctl = (MyControl) Page.LoadControl(“ctl.ascx”);• Note: This is not needed if you don’t explicitly cast control

Page 23: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Visual Studio Conversion

• New dynamic compilation model implications:– Code that calls Type.GetType(“SomeType”) will fail if

referencing classes in other code-behind files or in files deployed in App_Code

– Instead, use: System.Web.Compilation.BuildManager.GetType

• The ASP.NET BuildManager has extra logic to “look” at all ASP.NET related assemblies

• VS 2005 project migration wizard will update code that does this

Page 24: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Type Resolution

Page 25: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Visual Studio Conversion

• Developers can pre-compile an ASP.NET site with:– aspnet_compiler.exe command line tool– “Publish Website” menu option within VS 2005

• Two choices when pre-compiling:– All code compiled and .aspx markup removed– All code compiled, but .aspx preserved for later html

edits (note: this is new in Beta2 and now the default)

Page 26: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Application Pre-compilation

Page 27: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

Session Summary

• ASP.NET V1.1 and V2.0 run side-by-side on same server– No need to migrate all apps in order to start using V2.0

• Backwards compatibility a priority with new APIs and features– Please tell us in Beta2 when you find things that break

• VS 2005 auto upgrades existing web projects to use new project model– Provides significantly better flexibility for web projects– Need to be aware of a few implications of dynamic compilation model

• Things to-do today to prepare for ASP.NET V2.0:– Start making HTML markup XHTML compliant– Separate non-codebehind classes/enums into separate class files– Avoid class naming conflicts with new V2.0 features now where possible

Page 28: Migrating from ASP.NET 1.1 to ASP.NET 2.0 Scott Guthrie Web Platform and Tools Team Microsoft Corporation scottgu@microsoft.com

© 2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.