- •Contents
- •Introduction
- •Acknowledgments
- •The Goals of ASP.NET 2.0
- •Developer productivity
- •Administration and management
- •Performance and scalability
- •Device-specific code generation
- •Additional New Features of ASP.NET 2.0
- •New developer infrastructures
- •New compilation system
- •Additions to the page framework
- •New objects for accessing data
- •New server controls
- •A New IDE for Building ASP.NET 2.0 Pages
- •The Document Window
- •Views in the Document Window
- •The tag navigator
- •Page tabs
- •Code change status notifications
- •Error notifications and assistance
- •The Toolbox
- •The Solution Explorer
- •Lost Windows
- •Other Common Visual Studio Activities
- •Creating new projects
- •Making references to other objects
- •Using smart tags
- •Saving and importing Visual Studio settings
- •Application Location Options
- •Built-in Web server
- •Web site requiring FrontPage Extensions
- •The ASP.NET Page Structure Options
- •Inline coding
- •New code-behind model
- •New Page Directives
- •New attributes
- •New directives
- •New Page Events
- •Cross-Page Posting
- •New Application Folders
- •\Code folder
- •\Themes folder
- •\Resources folder
- •Compilation
- •The New Data Source Controls
- •The SqlDataSource and GridView Controls
- •Reading data
- •Applying paging in the GridView
- •Sorting rows in the GridView control
- •Defining bound columns in the GridView control
- •Enabling the editing of rows in the GridView control
- •Deleting data from the GridView
- •Dealing with other column types in the GridView
- •Selecting which fields to display in the DetailsView control
- •Using the GridView and DetailsView together
- •Updating, inserting, and deleting rows
- •XmlDataSource Control
- •ObjectDataSource Control
- •SiteMapDataSource Control
- •DataSetDataSource Control
- •Visual Studio 2005
- •Connection Strings
- •Site Maps
- •The PathSeparator property
- •The PathDirection property
- •The ParentLevelsDisplayed property
- •The ShowToolTips property
- •Examining the parts of the TreeView control
- •Binding the TreeView control to an XML file
- •Selecting multiple options in a TreeView
- •Specifying custom icons in the TreeView control
- •Specifying lines used to connect nodes
- •Working with the TreeView control programmatically
- •Applying different styles to the Menu control
- •Menu Events
- •Binding the Menu control to an XML file
- •SiteMap Data Provider
- •SiteMapViewType
- •StartingNodeType
- •SiteMap API
- •Why Do You Need Master Pages?
- •The Basics of Master Pages
- •Coding a Master Page
- •Coding a Content Page
- •Mixing page types and languages
- •Specifying which master page to use
- •Working with the page title
- •Working with controls and properties from the master page
- •Nesting Master Pages
- •Container-Specific Master Pages
- •Event Ordering
- •Caching with Master Pages
- •Using ASP.NET 2.0 Packaged Themes
- •Applying a theme to a single ASP.NET page
- •Applying a theme to an entire application
- •Applying a theme to all applications on a server
- •Removing themes from server controls
- •Removing themes from Web pages
- •Removing themes from applications
- •Creating Your Own Themes
- •Creating the proper folder structure
- •Creating a skin
- •Including CSS files in your themes
- •Having your themes include images
- •Defining Multiple Skin Options
- •Programmatically Working with Themes
- •Themes and Custom Controls
- •Authentication
- •Authorization
- •ASP.NET 2.0 Authentication
- •Setting up your Web site for membership
- •Adding users
- •Asking for credentials
- •Working with authenticated users
- •Showing the number of users online
- •Dealing with passwords
- •ASP.NET 2.0 Authorization
- •Using the LoginView server control
- •Setting up your Web site for role management
- •Adding and retrieving application roles
- •Deleting roles
- •Adding users to roles
- •Getting all the users of a particular role
- •Getting all the roles of a particular user
- •Removing users from roles
- •Checking users in roles
- •Using the Web Site Administration Tool
- •The Personalization Model
- •Adding a simple personalization property
- •Using personalization properties
- •Adding a group of personalization properties
- •Using grouped personalization properties
- •Defining types for personalization properties
- •Using custom types
- •Providing default values
- •Making personalization properties read-only
- •Anonymous Personalization
- •Enabling anonymous identification of the end user
- •Working with anonymous identification events
- •Anonymous options for personalization properties
- •Migrating Anonymous Users
- •Personalization Providers
- •Working with the Access personalization provider
- •Working with the SQL Server personalization provider
- •Using multiple providers
- •Building Dynamic and Modular Web Sites
- •Introducing the WebPartManager control
- •Working with zone layouts
- •Understanding the WebPartZone control
- •Explaining the WebPartPageMenu control
- •Modifying zones
- •Caching in ASP.NET 1.0/1.1
- •Output caching
- •Partial page caching
- •Data caching using the Cache object
- •Cache dependencies
- •ASP.NET 2.0 unseals the CacheDependency class
- •Enabling databases for SQL Server cache invalidation
- •Enabling tables for SQL Server cache invalidation
- •Looking at SQL Server
- •Looking at the tables that are enabled
- •Disabling a table for SQL Server cache invalidation
- •Disabling a database for SQL Server cache invalidation
- •Configuring your ASP.NET Application
- •Adding more than one table to a page
- •Attaching SQL Server cache dependencies to the Request object
- •Attaching SQL Server cache dependencies to the Cache object
- •Customizing the side navigation
- •Examining the AllowReturn attribute
- •Working with the StepType attribute
- •Adding a header to the Wizard control
- •Utilizing Wizard control events
- •Working with images from disk
- •Resizing images
- •Displaying images from streams
- •The MMC ASP.NET Snap-In
- •General
- •Custom Errors
- •Authorization
- •Authentication
- •Application
- •State Management
- •Advanced
- •ASP.NET Web Site Administration Tool
- •Home
- •Security
- •Profile
- •Application
- •Provider
- •Managing the Site Counter System
- •Generics
- •Iterators
- •Anonymous Methods
- •Operator Overloading
- •Visual Basic XML Documentation
- •New Visual Basic Keywords
- •Continue
- •Using
- •Global
- •Index
Personalization
Listing 9-22: Using SQL Server as the provider in the machine.config file
<configuration>
<system.web>
...
<profile enabled=”true” defaultProvider=”AspNetSqlProvider” inherits=”System.Web.Profile.HttpProfileBase, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”>
...
</profile>
...
</system.web>
</configuration>
This change forces each and every application that resides on this server to use the SQL Server provider instead of the Access provider, unless this command is overridden in the application’s web.config file.
Using multiple providers
You are not limited to using a single provider, such as the Access or SQL provider. Instead, you can use any number of providers. You can specify the personalization provider for each property defined. This means that you can use the default provider for most of the properties, whereas a few of them use an entirely different provider (see Listing 9-23).
Listing 9-23: Using different providers
<configuration>
<system.web>
<profile inherits=”System.Web.Profile.HttpProfileBase, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”
defaultProvider=”AspNetSqlProvider”>
<properties>
<add name=”FirstName” /> <add name=”LastName” /> <add name=”LastVisited” /> <add name=”Age” />
<add name=”Member” provider=”AspNetAccessProvider” />
</properties>
</profile>
</system.web>
</configuration>
289
Chapter 9
From this example, you can see that a default provider is specified — AspNetSqlProvider. Unless specified otherwise, this provider is used. The only property that changes this setting is the property Member. The Member property uses an entirely different personalization provider. In this case, it employs the Access provider (AspNetAccessProvider) through the use of the provider attribute of the <add> element. With this attribute, you can define a specific provider for each and every property that is defined.
Summar y
The new personalization capabilities provided by ASP.NET 2.0 make it incredibly easy to make your Web applications unique for all end users, whether they are authenticated or anonymous. This new system enables you to store everything from basic data types provided by the .NET Framework to custom types that you create. This system is more versatile and extensible than the use of Session or Application objects. The data is stored via a couple of built-in personalization providers that ship with ASP.NET. These providers include ones that connect with either Microsoft Access or Microsoft SQL Server.
290
Por tal Frameworks and Web Par ts
Internet and intranet applications have changed considerably since their introduction in the 1990s. Today’s applications don’t simply display the same canned information to every viewer; they do much more. Because of the wealth of information exposed to end users, Internet and intranet applications must integrate large amounts of customization and personalization into their offerings.
Web sites that provide a plethora of offerings give end users the option to choose which parts of the site they want to view and which parts they want to hide. Ideally, end users can personalize the pages, deciding for themselves the order in which the content appears on the page. They should be able to move items around on the page as if it were a design surface.
After pages are customized and established, the end user needs the capability to export his settings for storage. You certainly wouldn’t want to allow an end user to highly customize a page or a series of pages in your portal and then force him to reapply the settings each time he visits the site. Instead, developers need to take these setting points and move the items to a data store for later exposure.
Adding this kind of functionality is expensive — expensive in the sense that it can take a considerable amount of work on the part of the developer. Before ASP.NET 2.0, the developer had to build a personalization framework that would be used by each page requiring the functionality. This type of work is error prone and difficult to achieve, which is why in most cases it wasn’t developed.
But wait. . . .
Introducing Web Par ts
To make it easier to retain the page customization settings applied to your page by your application’s end users, Microsoft has included Web Parts in this release of ASP.NET. Web Parts, part of the larger Portal Framework, are an outstanding way to build a modular Web site that can be customized with dynamically reapplied settings on a per-user basis. Web Parts are objects in the
Chapter 10
Portal Framework which the end user can open, close, minimize, maximize or move from one part of the page to another.
The Portal Framework enables you to build pages that contain multiple Web Parts — which are part of the ASP.NET server control framework and are used like any of the other ASP.NET server controls. This means that you can also extend Web Parts if necessary.
The components of the Portal Framework provide the means to build a truly dynamic Web site, whether that site is a traditional Internet site, an intranet site, a browser-based application, or any other typical portal.
When you first look at Web Parts in ASP.NET 2.0, it may remind you of Microsoft’s SharePoint Portal Server. Be forewarned, however, that these two technologies are similar in name only. The ASP.NET team introduced Web Parts; the resulting Portal Framework is the basis of what is now also used by the SharePoint Portal Server, in addition to being offered in ASP.NET. Microsoft is simply creating singular technologies that can be used by other Microsoft offerings. In this process, Microsoft is trying to reach the Holy Grail of computing — code reuse!
The modular and customizable sites that you can build with the new Portal Framework enable you to put the Web page that is in view in several possible modes for the end user. The following list describes each of the available modes and what each means to the end user viewing the page:
Normal Mode: Puts the page in a normal state, which means that the end user cannot edit or move sections of the page. This is the mode used for standard page viewing.
Edit Mode: Enables end users to select particular sections on the page for editing. The selected section allows all types of editing capabilities from changing the part’s title, the part’s color, or even setting custom properties — such as specifying the end user’s zip code to pull up a customized weather report.
Design Mode: Enables end users to rearrange the order of the page’s modular components. The end user can bring items higher or lower within a zone, delete items from a zone, or move items from one page zone to another.
Catalog Mode: Displays a list of available sections (Web Parts) that can be placed in the page. Catalog Mode also allows the end user to select in which zone on the page the items should appear.
Figure 10-1 shows a screen shot of a portal utilizing the Portal Framework with the Edit Mode selected.
The Portal Framework is a comprehensive and thought-out framework that enables you to incorporate everything you would normally include in your ASP.NET applications. You can apply security using either Windows Authentication or Forms Authentication. This framework also enables you to leverage the other new aspects of ASP.NET 2.0, such as applying role management, personalization, and membership features to any portal that you build.
To understand how to build your own application on top of the new Portal Framework, start by creating a simple page that uses this new framework’s utilities.
292
