- •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
Application and Page Frameworks
In order to see the Finnish text, add the following Page directive:
uiculture=”fi-FI”
After this is in place, run the page. You see the Finnish language output shown in Figure 3-13.
Figure 3-13
Compilation
You already saw how Visual Studio 2005 compiles pieces of your application as you work with them (for instance, by placing a class in the \Code folder). The rest of the application, such as the .aspx pages themselves can be compiled just as in ASP.NET 1.0/1.1 by referencing the pages in the browser.
When an ASP.NET page is referenced in the browser for the first time, the request is passed to the ASP.NET parser that creates the class file in the language of the page. After the class file has been created, the class file is compiled into a DLL and then written to the disk of the Web server. This is detailed in Figure 3-14.
On the next request, great things happen. Instead of going through the entire process again for the second and respective requests, the request simply causes an instantiation of the already-created DLL, which sends out a response to the requester. This is illustrated in Figure 3-15.
Because of the mechanics of this process, if you made changes to your .aspx code-behind pages, you found it necessary to recompile your application. This can be quite a pain if you have a larger site and don’t want your end users to experience the extreme lag that occurs when an .aspx page is referenced for the first time after compilation. Many developers, consequently, began to develop their own tools that would automatically go out and hit every single page within their application to remove this firsttime lag hit from the end user’s browsing experience.
69
Chapter 3
|
Parse |
Request |
.ASPX |
|
File |
Response
Figure 3-14
Parse
Request
.ASPX File
2nd Request
Response
Figure 3-15
ASP.NET
Code-
Engine
Behind
Class
Generate
Generated
Page Compile
Class
Instantiate,
process, and Page render
Class
ASP.NET
Code-
Engine
Behind
Class
Generate
2nd Request
Instantiation Generated
Page Compile Class
Instantiate,
process, and Page render
Class
ASP.NET 2.0 introduces the technology to precompile your entire application with a single command that you can issue directly in the browser. This type of compilation is referred to as in-place precompilation. In order to precompile your entire ASP.NET application, pull up one of the pages in the browser and replace the page name with precompile.axd. So, if you are working with the Web server that is built into Visual Studio 2005, your request is structured in the following format:
70
Application and Page Frameworks
http://[host]:[port]/[Application Name]/precompile.axd
If you are using IIS as the Web server, your request is structured in the following format:
http://[host]/[Application Name]/precompile.axd
If it is successful, you get a message that states the precompilation was successful. The other great thing about this precompilation capability is that you can also use it to find any errors on any of the ASP.NET pages in your application. Because it hits each and every page, if one of the pages contains an error that won’t be triggered until runtime, you get notification of the error immediately as you invoke precompile.axd.
The next precompilation option is commonly referred to as precompilation for deployment. This is an outstanding new addition to ASP.NET that enables you to compile your application down to some DLLs, which can then be deployed to customers, partners, or elsewhere for your own use. Not only are minimal steps required to do this, but after your application is compiled, you only have to move around the DLL and some placeholder files for the site to work. This means that your Web site code is completely removed and placed in the DLL when deployed.
To precompile your application for deployment, you must use the aspnet_compiler.exe tool that now comes with ASP.NET 2.0. You navigate to the tool using the Command window. Open the Command window and navigate to C:\Windows\Microsoft.NET\Framework\v2.0.xxxxx\. When you are there, you can work with the aspnet_compiler tool.
Before you do, however, create a folder in your root drive called, for example, Wrox. This folder is the one you ask the compiler to output to. When it is in place, you can return to the compiler tool and give it the following command:
aspnet_compiler -v [Application Name] –p [Physical Location] [Target]
So, if you had an application called INETA located at C:\Websites\INETA, you would use the following commands:
aspnet_compiler –v /INETA –p C:\Websites\INETA C:\Wrox
Press Return and the compiler either tells you that it has a problem with one of the command parameters, or that it was successful (shown in Figure 3-16). If it was successful, you can see the output that was placed in the target directory.
Figure 3-16
71
Chapter 3
In the example just shown, -v is a command for the virtual path of the application — which is provided by using /INETA. The next command is –p, which is pointing to the physical path of the application. In this case, it is C:\Websites\INETA. Finally, the last bit, C:\Wrox, is the location of the compiler output. The following table describes the possible commands for the aspnet_compiler.exe tool.
Command |
Description |
|
|
-m |
Specifies the full IIS metabase path of the application. If you use the -m |
|
command, you cannot use the -v or -p commands. |
-v |
Specifies the virtual path of the application that is going to be compiled. |
|
If you also use the -p command, the physical path is used to find the |
|
location of the application. |
-p |
Specifies the physical path of the application that is going to be compiled. |
|
If this is not specified, the IIS metabase is used to find the application. |
targetDir |
Specifies the target directory where the compiled files should be placed. If |
|
this is not specified, the files output are placed in the application directory. |
|
|
After compiling the application, you can go to C:\Wrox to see the output. Here you see all the files and the file structure that was in the original application. But if you look at the contents of one of the files, notice that the file is simply a placeholder. In the actual file you find the comment:
This is a marker file generated by the precompilation tool, and should not be deleted!
In fact, you find a Code.dll file in the bin folder where all the page code is located. Because it is in a DLL file, is provides great code obfuscation as well. From here on, all you do is move these files to another server using FTP or Windows Explorer and you can run the entire Web application from these files. When you have an update to the application, you simply provide a new set of compiled files. A sample output is displayed in Figure 3-17.
Figure 3-17
72
Application and Page Frameworks
Note that this compilation process doesn’t compile every type of Web file. In fact, it compiles only the ASP.NET-specific file types and leaves out of the compilation process files such as
HTML files
XML files
XSD files
Web.Config files
Text files
You can’t do much to get around this, except in the case of the HTML files and the text files. For these file types, just change the file extension to .aspx and they are then compiled into the Code.dll like all the other ASP.NET files.
Summar y
This chapter covered a lot of ground. I discussed some of the issues concerning ASP.NET applications as a whole and the choices you have when building and deploying these new applications. With the help of Visual Studio 2005, you now have options about which Web server to use when building your application and whether to work locally or remotely through the new built-in FTP capabilities.
ASP.NET 2.0 and Visual Studio 2005 make it easy to build your pages using an inline coding model or to select a new and better code-behind model that is simpler to use and easier to deploy. You also took a look at the new cross-posting capabilities and the new fixed folders that ASP.NET 2.0 has incorporated to make your life easier. These folders make their resources available dynamically with no work on your part. Finally, you saw some of the outstanding new compilation options that you have at your disposal.
As you worked through some of the examples, you may have been thinking, “WOW!” But wait . . .
there’s plenty more to come!
73
