Anda di halaman 1dari 66

ASAP to ASP.NET 2.

Noam King CTO Sela youniversity

Agenda
Introduction Architecture Master Pages Personalization Building a site with Web Parts. Skins and Themes Administration & Management Site Navigation (Optional) Handling data with ASP.NET 2.0 (Optional) Summary

Introduction to ASP.NET 2.0


Controls
Data Controls Login Controls Other New Controls

Web Parts

Page Framework

Master Pages

Themes and Skins

Mobility and Localization

Compilation

Services and APIs

Membership

Role Management
Site Maps Health Monitoring

Profiles

Configuration

Other Services

Architecture

Architecture Code Model


ASP 1.1 ASP 2.0

Architecture Coding Model (cont.)


Reduced Inheritance Complexity
No need for declaration code Code is linked by VS2005 and the runtime

Reduced Compilation Complexity


Code-behind automatically synchronized with aspx page More compilation models

Architecture Coding Model (cont.) Compilation


Normal
Similar to Asp 1.1

Batch Compilation
Like in asp1.1 <compilation batch="true|false" batchTimeout="number of seconds" maxBatchSize="maximum number of pages per batched compilation" maxBatchGeneratedFileSize="maximum combined size (in KB) of the generated source file per batched compilation </compilation>

Architecture Coding Model (cont.) Compilation (cont.)


Deployment pre-compilation
aspnet_compiler /v /<websitename> p <source> HTML pages, resources, configuration files, and ASPX pages are copied separately. Stub files for the various aspx pages. Increased performance and increased security.

Architecture Coding Model (cont.) Compilation (cont.)


In Place Compliation
http://localhost/mywebsitename/precompile.axd Eliminate performance hit of batch compilation Let you find compilation errors before your users do.

Full Runtime Compilation (The Code Directory)


the \Code directory is designed for storing class files to be compiled dynamically at run time. Simple deployment

Architecture Page LifeCycle


Constructor Construct TestDeviceFilter AddParsedSubObject DeterminePostBackMode OnPreInit LoadPersonalizationData InitializeThemes OnInit ApplyControlSkin ApplyPersonalization OnInitComplete LoadPageStateFromPersistenceMedium (PB) LoadControlState (PB) LoadViewState (PB) ProcessPostData1 OnPreLoad OnLoad ProcessPostData2 (PB) RaiseChangedEvents (PB) RaisePostBackEvent (PB) OnLoadComplete OnPreRender OnPreRenderComplete SavePersonalizationData SaveControlState SaveViewState SavePageStateToPersistenceMedium Render OnUnload

PB = Post Back

Architecture Code Page Posting


If Page.IsCrossPagePostBack Then Label1.Text = Hello & PreviousPage.pp_Textbox1.Text & <br /> & _ Date Selected: & _ PreviousPage.pp_Calendar1.Sele ctedDate.ToShortDateString() Else Response.Redirect(Page1.aspx) End If

Architecture - Extensibilty
New HttpModules SessionID Role Management Anonymous Identification Profile Page Counters New Handlers

WebAdminHandler
TraceHandler WebResourcesHandler PrecomHandler More

Architecture Performance
Improved Request Pipeline
Up to 30% percent improved request stack

Improved Memory management with IIS6


Working set for the worker process reduced by around 50%. General improvements on II6

More to come in the release

Master Pages

Master Pages - Basics


Masters define common content and placeholders (<asp:ContentPlaceHolder>) Content pages reference masters and fill placeholders with content (<asp:Content>)
Site.master
<%@ Master %>

default.aspx
<%@ Page MasterPageFile="Site.master" %> <asp:Content ContentPlaceHolderID= "Main" RunAt="server" />

http://.../default.aspx

<asp:ContentPlaceHolder ID="Main" RunAt="server" />

</asp:Content>

Master Pages Defining and applying


Defining
<%@ Master %>

Applying
<%@ Page MasterPageFile="~/Site.master" %> <asp:Content ContentPlaceHolderID="Main" RunAt="server"> This content fills the place holder "Main" defined in the master page </asp:Content>

Master Pages
Applying to a site
<configuration> <system.web> <pages masterPageFile="~/Site.master" /> </system.web> </configuration>

Applying Programmatically
Sub Page_PreInit (ByVal sender As Object,ByVal e As EventArgs) Page.MasterPageFile = "~/Site.master" End Sub

Master Pages Weak Typing

In the master page


<asp:Label ID="Title" RunAt="server" />

In the content page


(CType(Master.FindControl ("Title"), Label).Text = "Orders"

Master Pages Strong Typing


In the master page
<asp:Label ID="Title" RunAt="server" /> . . . <script language=VB" runat="server"> Public Property TitleText as string Get return Title.Text End Get Set Title.Text = value End Set End Property </script>

In the content page


Master.TitleText = "Orders"

Master Pages - Nesting


Master Page IDF (idf.master)

Master Page IDF North (idfnorth.master)

Master Page IDF South (idfsouth.master)

Content page1 (default.aspx)

Content Page2 (default2.aspx)

Content Page3 (default3.aspx)

Content Page4 (default4.aspx)

Master Pages Nesting (cont.)


Master pages that have masters must contain only Content controls, but Content controls can contain ContentPlaceHolders

<!-- Orders.Master --> <%@ Master MasterPageFile="~/Site.Master" %> <asp:Content ContentPlaceHolderID="..." RunAt="server"> <asp:ContentPlaceHolder ID="..." RunAt="server"> ... </asp:ContentPlaceHolder> <asp:Content>

Master Pages - Container-Specific


<%@ Page Language=VB MasterPageFile=~/Sela.master Mozilla:MasterPageFile=~/SelaMozilla.maste r Opera:MasterPageFile=~/SelaOpera.master %> <asp:Content ID=Content1 ContentPlaceHolderId=ContentPlaceHolder1 Runat=server> Hello World

Master Pages Event order


Master page child controls initialization Content page child controls initialization Master page initialization Content page initialization Content page load Master page load Master page child controls loadContent page child controls load

Personalization

Personalization - Overview
Automatic association between the end user viewing the page and any data points stored for that user. The personalization properties that are maintained on a per-user basis are stored on the server and not on the client. The end user can access these personalization properties on later site visits. Ideal way to start creating highly customizable and user-specific sites without massing with all the underlined code.

Personalization Defining & Using


Configuration <configuration> <system.web> <profile> <properties> <add name=FirstName /> <add name=LastName /> </properties> </profile> </system.web> </configuration> Using Profile.FirstName = TextBox1.Text

Personalization - Groups
Configuration <group name=MemberDetails> <add name=Member /> <add name=DateJoined /> <add name=PaidDuesStatus /> <add name=Location /> </group>

Using

Label1.Text = Profile.MemberDetails.DateJoined

Personalization - Types
Define types to the fields Use default values to the fields Define readonly for fields Create custom types for fields and serialization type.

<add name=Field name type=FieldType serializeAs=Binary />

Web Parts

Web Parts
Orchestrates operation of Web Parts
Maintains list of Web Parts and zones Manages page state (e.g., display mode) and fires events when page state changes Facilitates communication between Web Parts Manages personalization and much more

One instance per page; not a visible control.


<asp:WebPartManager ID="WebPartManager1" RunAt="server" />

Web Parts - WebPartZone


Defines zones on a Web Parts page Defines default layout and appearance of Web Parts within each zone
<asp:WebPartZone ID="WeatherZone" DragHighlightColor="244,198,96" RunAt="server"> <PartTitleStyle BackColor="#2254B1" ForeColor="White" /> <PartStyle BorderColor="#81AAF2" BorderStyle="Solid" BorderWidth="1px" /> <ZoneTemplate> <!-- Web Parts declared here --> </ZoneTemplate> </asp:WebPartZone>

Web Parts - Controls


Controls defined in a WebPartZone
Web controls, user controls, custom controls

Controls that don't implement IWebPart are internally wrapped in GenericWebParts


Adds properties: Title, Description, etc.
<ZoneTemplate> <asp:Calendar Title="Calendar" ID="Calendar1" RunAt="server" /> <user:Weather Title="Weather" ID="Weather1" RunAt="server" /> <custom:Search Title="Search" ID="Search1" RunAt="server" /> </ZoneTemplate>

Web Parts WebPartManager & WebPartPage Menu


Gets and sets the page's display mode
Value
BrowserDisplayMode DesignDisplayMode EditDisplayMode CatalogDisplayMode ConnectDisplayMode

Description
"Normal" display mode; no editing (default) Permits drag-and-drop layout editing Permits editing of Web Parts' appearance and behavior Permits Web Parts to be added to the page Permits connections to be established between Web parts

<asp:WebPartPageMenu ID=Webpartpagemenu1 Runat=server> </asp:WebPartPageMenu>

Web Parts Catalog Zone


<asp:CatalogZone ID="CatalogZone1" Runat="server"> <ZoneTemplate> <asp:PageCatalogPart ID="PageCatalogPart1" Runat="server" /> <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" Runat="server"> <WebPartsTemplate> <!-- Declarative Web Parts go here --> </WebPartsTemplate> </asp:DeclarativeCatalogPart> <asp:ImportCatalogPart ID="ImportCatalogPart1" Runat="server" /> </ZoneTemplate> </asp:CatalogZone>

DeclarativeCatalogPart

Web Parts - EditorZone


<asp:EditorZone ID="EditorZone1" Runat="server"> <ZoneTemplate> <asp:AppearanceEditorPart ID="AppearanceEditorPart1" Runat="server" /> <asp:BehaviorEditorPart ID="BehaviorEditorPart1" Runat="server" /> <asp:LayoutEditorPart ID="LayoutEditorPart1" Runat="server" /> </ZoneTemplate> </asp:EditorZone>

Web Parts Custom Web Parts


Any control can serve as a Web Part, but Controls that derive from WebPart can better leverage the Web Parts infrastructure
Control Title and other UI-related properties Control AllowClose, AllowZoneChange, AllowMinimize, and other behavioral properties Apply role-based security (authorization filters) Add custom verbs, export Web Parts, and more

Web Parts Custom Web Parts (cont.)


public class MyWebPart : WebPart { public override WebPartVerbCollection Verbs { get { EnsureChildControls (); WebPartVerb verb = new WebPartVerb (new WebPartEventHandler (OnClearResults)); verb.Text = "Clear Results"; WebPartVerb[] verbs = new WebPartVerb[] { verb }; return new WebPartVerbCollection (base.Verbs, verbs); } } void OnClearResults (object sender, WebPartEventArgs args) { ... } ...

Skins And Themes

Skins and Themes - Overview


Mechanism for theming controls, pages, and sites by group-initializing control properties Skin = Visual attributes for control(s)
Physically stored in .skin files Default skins and named skins

Theme = Collection of one or more skins


Physically stored in Themes subfolders Global themes and local themes

Skins and Themes - Applying


On a page
<%@ Page Theme="BasicBlue">

On a Site
<configuration> <system.web> <pages theme="BasicBlue" /> </system.web> </configuration>

Programmatically
Sub Page_PreInit (ByVal sender As Object, ByVal e As EventArgs) Page.Theme = "BasicBlue" End Sub

Skins And Themes Global


ASP.NETClientFiles

Theme name = Subdirectory name


Themes

SKIN

BasicBlue

SKIN

SmokeAndGlass

SKIN SKIN

Skins and Themes - Local


vroot

Theme name = Subdirectory name


Themes

ShockingPink

SKIN SKIN

AutumnLeaves

SKIN SKIN

Skins and Themes Named Skins


Skins without SkinIDs are default skins Skins with SkinIDs are named skins
SkinIDs must be unique per control type Can be defined in same SKIN file as default skins or in separate files

Use controls' SkinID properties to apply named skins

Skins and Thems Named Skins (Defining and Using)


<!-- Default look for DropDownList controls --> <asp:DropDownList runat="server" BackColor="blue" ForeColor="white" SkinID="Blue" /> <!-- Default look for DataGrid conotrols --> <asp:DataGrid runat="server" BackColor="#CCCCCC" BorderWidth="2pt" BorderStyle="Solid" BorderColor="#CCCCCC" GridLines="Vertical" HorizontalAlign="Left" SkinID="Blue"> <HeaderStyle ForeColor="white" BackColor="blue" /> <ItemStyle ForeColor="black" BackColor="white" /> <AlternatingItemStyle BackColor="lightblue" ForeColor="black" /> </asp:DataGrid> ...

<asp:DropDownList ID="Countries" SkinID="Blue" RunAt="server" />

Administration & Management

A&M - Overview
Administrative tools
ASP.NET MMC snap-in Web Site Administration Tool (Webadmin.axd)

Configuration API
Read/write access to configuration settings Simplified custom configuration sections

Instrumentation
Perf counters, health monitoring, and more

A&M ASP.NET MMC Snap-In


GUI for applying configuration settings

A&M Web Site Administration Tool (WAT)


Browser-based admin GUI

Invoked by requesting Webadmin.axd or using the "ASP.NET Configuration" command in Visual Studio's Website menu

A&M Configuration class


Gateway to the configuration API Provides merged view of configuration settings for machine or application AppSettings and ConnectionStrings properties provide access to <appSettings> and <connectionStrings> sections Sections and SectionGroups properties provide access to all other sections

A&M Configuration Class Methods


Name
GetExeConfiguration

Description
Returns a Configuration object representing config settings for a managed EXE Returns a Configuration object representing configuration settings for the specified server Returns a Configuration object representing configuration settings for the specified Web application Returns a ConfigurationSectionGroup object representing the specified section group Returns a ConfigurationSection object representing the specified section (e.g., <appSettings> Records changes in the relevant configuration file

GetMachineConfiguration

GetWebConfiguration

GetSectionGroup

GetSection

Update

A&M Configuration class properties


Name
AppSettings

Description
Returns an AppSettingsSection object representing the <appSettings> section Returns a ConnectionStringsSection object representing the <connectionsStrings> section True if there's a corresponding configuration file, false if not Path to the app represented by this Configuration object Returns a ConfigurationSectionGroupCollection representing all section groups Returns a ConfigurationSectionCollection representing all sections

ConnectionStrings

HasFile Path SectionGroups

Sections

A&M Configuration example (Reading Connection String)


Read a connection string from <connectionStrings> Dim connect As string = ConfigurationSettings.ConnectionStrings("Northwind).ConnectionString Add a connection string to <connectionStrings> Dim config As Configuration = Configuration.GetWebConfiguration (Request.ApplicationPath) config.ConnectionStrings.ConnectionStrings.Add (new ConnectionStringSettings ("Northwind", "server=localhost;database=northwind;integrated security=true") config.Update () // Important!

A&M ASP.NET Instrumentation


Name
Performance counters

Description
New peformance counters supplement the ones introduced in ASP.NET 1.x Integration with ETW subsystem to support low-overhead tracing of HTTP requests through the system ASP.NET trace facility upgraded with new features and to allow coupling to System.Diagnostics.Trace New provider-based subsystem for logging notable events ("Web events") that occur during an application's lifetime

Windows event tracing

Application tracing

Health monitoring

Handling Data

Handling Data DataSource control


SqlDataSource Enables you to work with any SQL-based database, such as Microsoft SQL Server or Oracle. AccessDataSource Enables you to work with a Microsoft Access file (.mbd). ObjectDataSource Enables you to work with a business object or a Visual Studio 2005 data component. XmlDataSource Enables you to work with the information from an XML file or an XML source (for example an RSS feed). SiteMapDataSource Enables you to work with the hierarchical data represented in the site map file (.sitemap). DataSetDataSource Enables you to work with data that is represented in a DataSet object.

Handling Data Data Bound Server controls


<asp:GridView> <asp:DataGrid> <asp:DetailsView> <asp:TreeView> <asp:Menu> <asp:DataList> <asp:Repeater> <asp:DropDownList> <asp:BulletedList> <asp:CheckBoxList> <asp:RadioButtonList> <asp:ListBox> <asp:AdRotator>

Site Navigation

Site Navigation - Overview


Navigation UIs are tedious to implement
Especially if they rely on client-side script

New controls simplify site navigation


TreeView and Menu - Navigation UI SiteMapDataSource - XML site maps SiteMapPath - "Bread crumb" controls

Public API provides foundation for controls Provider-based for flexibility

Site Navigation - Schema


Controls
Menu TreeView SiteMapDataSource SiteMapPath

Site Navigation API


SiteMapNode

SiteMap SiteMapNode SiteMapNode

Providers

XmlSiteMapProvider

Other Site Map Providers

Site Maps
Web.sitemap Other Data Stores

Site Navigation TreeView Example


<asp:TreeView ShowLines="true" Font-Name="Verdana" Font-Size="10pt" ... > <SelectedNodeStyle BackColor="Yellow" /> <HoverNodeStyle BackColor="LightBlue" /> <Nodes> <asp:TreeNode Text="Not selectable" SelectAction="None" RunAt="server"> <asp:TreeNode Text="Selectable" SelectAction="Select" RunAt="server" > <asp:TreeNode Text="Click to expand or collapse" SelectAction="Expand" Runat="server"> <asp:TreeNode Text="Click to select and expand or collapse" SelectAction="SelectExpand" Runat="server"> <asp:TreeNode Text="Check box node" ShowCheckBox="true" Runat="server"> <asp:TreeNode Text="Click to navigate" NavigateUrl="..." Runat="server" /> </asp:TreeNode> </asp:TreeNode> </asp:TreeNode> </asp:TreeNode> </asp:TreeNode> </Nodes> </asp:TreeView>

Site Navigation Menu Control

<asp:Menu Orientation="Horizontal" RunAt="server"> <Items> <asp:MenuItem Text="Training" RunAt="server"> <asp:MenuItem Text="Programming .NET" RunAt="server" Navigateurl="Classes.aspx?id=1" /> <asp:MenuItem Text="Programming ASP.NET" RunAt="server" NavigateUrl="Classes.aspx?id=2" /> <asp:MenuItem Text="Programming Web Services" RunAt="server" NavigateUrl="Classes.aspx?id=3" /> </asp:MenuItem> <asp:MenuItem Text="Consulting" RunAt="server" NavigateUrl="Consulting.aspx" /> <asp:MenuItem Text="Debugging" RunAt="server" NavigateUrl="Debugging.aspx" /> </Items> </asp:Menu>

Site Navagation - SiteMap

<siteMap> <siteMapNode title="Home" description="" url="default.aspx"> <siteMapNode title="Training" url="Training.aspx" description="Training for .NET developers"> <siteMapNode title="Programming .NET" url="Classes.aspx?id=1" description="All about the .NET Framework" /> <siteMapNode title="Programming ASP.NET" url="Classes.aspx?id=2" description="All about ASP.NET" /> <siteMapNode title="Programming Web Services" url="Classes.aspx?id=3" description="All about Web services" /> </siteMapNode> <siteMapNode title="Consulting" url="Consulting.aspx" description="Consulting for .NET projects" /> <siteMapNode title="Debugging" url="Debugging.aspx" description="Help when you need it the most" /> </siteMapNode> </siteMap>

Site Navigation TreeView and SiteMap


<asp:SiteMapDataSource ID="SiteMap" RunAt="server" /> <asp:TreeView DataSourceID="SiteMap" RunAt="server" />

Web.sitemap
<siteMap> <siteMapNode title="Home" description="" url="default.aspx"> <siteMapNode title="Training" url="Training.aspx" description="Training for .NET developers"> <siteMapNode title="Programming .NET" url="Classes.aspx?id=1" description="All about the .NET Framework" /> <siteMapNode title="Programming ASP.NET" url="Classes.aspx?id=2" description="All about ASP.NET" /> <siteMapNode title="Programming Web Services" url="Classes.aspx?id=3" description="All about Web services" /> </siteMapNode> <siteMapNode title="Consulting" url="Consulting.aspx" description="Consulting for .NET projects" /> <siteMapNode title="Debugging" url="Debugging.aspx" description="Help when you need it the most" /> </siteMapNode> </siteMap>

Site Navigation Menu and SiteMap


<asp:SiteMapDataSource ID="SiteMap" RunAt="server" /> <asp:Menu DataSourceID="SiteMap" RunAt="server" />

Web.sitemap
<siteMap> <siteMapNode title="Home" description="" url="default.aspx"> <siteMapNode title="Training" url="Training.aspx" description="Training for .NET developers"> <siteMapNode title="Programming .NET" url="Classes.aspx?id=1" description="All about the .NET Framework" /> <siteMapNode title="Programming ASP.NET" url="Classes.aspx?id=2" description="All about ASP.NET" /> <siteMapNode title="Programming Web Services" url="Classes.aspx?id=3" description="All about Web services" /> </siteMapNode> <siteMapNode title="Consulting" url="Consulting.aspx" description="Consulting for .NET projects" /> <siteMapNode title="Debugging" url="Debugging.aspx" description="Help when you need it the most" /> </siteMapNode> </siteMap>

Site Navigation SiteMap API


Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Hyperlink1.Text = SiteMap.CurrentNode.ParentNode.ToString() Hyperlink1.NavigateUrl = SiteMap.CurrentNode.ParentNode.Url Hyperlink2.Text = SiteMap.CurrentNode.PreviousSibling.ToString() Hyperlink2.NavigateUrl = SiteMap.CurrentNode.PreviousSibling.Url Hyperlink3.Text = SiteMap.CurrentNode.NextSibling.ToString() Hyperlink3.NavigateUrl = SiteMap.CurrentNode.NextSibling.Url End Sub <html xmlns=http://www.w3.org/1999/xhtml > <head runat=server> <title>SiteMapDataSource</title> </head> <body> <form id=form1 runat=server> Move Up: <asp:Hyperlink ID=Hyperlink1 Runat=server></asp:Hyperlink><br /> <-- <asp:Hyperlink ID=Hyperlink2 Runat=server></asp:Hyperlink> | <asp:Hyperlink ID=Hyperlink3 Runat=server></asp:Hyperlink> --> </form> </body> </html>

Summary ASAP.Net
New features to simplify repetitive coding tasks New provider model offers extra extensibility New compilation model fixes old base/derived class problem Its stronger, faster, prettier and with a better engine. Wouldnt you like to give it a test drive ?

Anda mungkin juga menyukai