Configuring, Optimizing, and
Deploying a Microsoft
ASP.NET Web Application
Module 15: Configuring, Optimizing, and
Deploying a Microsoft ASP.NET Web Application
• Implementing the Cache Object
• ASP.NET Output Caching
• Configuring an ASP.NET Web Application
• Deploying an ASP.NET Web Application
Lesson: Implementing the Cache Object
• What Is the Cache Object?
• Advantages of Using the Cache Object
• How to Use the Cache Object
• Removing Items from the Cache Object
What Is the Cache Object?
• An object used to store information
One Cache object per Web Application
An alternative to application variables
Not used to store information in session variables
• Uses key-value pairs to store and retrieve items
Cache("myKey") = myValue
Cache["myKey"] = myValue;
Advantages of Using the Cache Object
• Faster than creating a new object for each request
• Supports internal locking
• Automatic cache resource management
• Supports callback functions
• Supports removal based on dependencies
How to Use the Cache Object
• Writing to the Cache object:
'Implicit method
Cache("myKey") = myValue
'Explicit method
Cache.Insert("myKey", myValue, Dependency, AbsoluteExpiration, _
SlidingExpiration, CacheItemPriority, CacheItemRemovedCallBack)
//Implicit method
Cache["myKey"] = myValue;
//Explicit method
Cache.Insert("myKey", myValue, Dependency, AbsoluteExpiration,
SlidingExpiration, CacheItemPriority, CacheItemRemovedCallBack);
• Retrieving values from the Cache object:
myValue = Cache("myKey") myValue = Cache["myKey"];
Removing Items from the Cache Object
• AbsoluteExpiration time
DateTime.Now.AddMinutes(5)
• SlidingExpiration time
TimeSpan.FromSeconds(20)
• Dependent on a changed value
AddCacheItemDependency("Variable.Value")
• Cache item priority
CacheItemPriority.High
Lesson: ASP.NET Output Caching
• Multimedia: Output Caching
• Output Cache Types
• Implementing Page Output Caches
• Implementing Control Caching
Multimedia: Output Caching
Output Cache Types
• Page caching
• Page fragment caching as a user control
• XML Web service caching
Implementing Page Output Caches
• Cache content is generated from dynamic pages
• Entire Web page is available in cache
• Set cache duration in seconds
• Set the VaryByParam property to control the number of
page variations in the cache
<%@ OutputCache Duration="900"
VaryByParam="none" %>
Implementing Control Caching
• Convert the page fragment into a user control
• Set the Duration and varyByParam properties
<%@ OutputCache Duration="120"
VaryByParam="none" %>
Lesson: Configuring an ASP.NET Web Application
• Overview of Configuration Methods
• Configuring a Web Server by Using Machine.config
• Configuring an Application by Using Web.config
• Configuration Inheritance
• Demonstration: Configuration Inheritance
• Storing and Retrieving Data in Web.config
• Implementing Dynamic Properties
Overview of Configuration Methods
• Machine.config file
Machine-level settings
• Web.config files
Application and directory-level settings
• Both Machine.config and Web.config files are:
Well-formed XML
camelCase
Extendable
Configuring a Web Server by Using
Machine.config
• Settings in the Machine.config file affect all Web
applications on the server
Only one Machine.config file per Web server
Most settings can be overridden at the application level by
using Web.config files
Configuring an Application by Using Web.config
• One or more Web.config files per Web application
• All configuration information for the application is
contained in the Web.config files
• Contains a section for each major category of ASP.NET
functionality
Security
Mode
General application settings
Tracing
Configuration Inheritance
• Application-level
CONFIG
CONFIG Web.config file inherits
settings from
Machine.config file
Machine.config
• Settings in Web.config
VirtualDir
file that conflict
VirtualDir
override inherited
settings
Web.config
• Individual directories
may have Web.config
SubDir
SubDir files that inherit from—
and can override—
application-level
Web.config
settings
Demonstration: Configuration Inheritance
• Create a subfolder that contains a Web.config file
• Show differences between the main Web.config file and
the subfolder's Web.config file
• Demonstrate how the Web Form reads information from
the Web.config files
• Delete the Web.config file from the subfolder and refresh
the Web Form
Storing and Retrieving Data in Web.config
• Configuring Web.config by using the Web Site
Administration Tool
• Storing application settings in a Web.config file
<configuration>
<appSettings>
<add key="pubs" value="server=localhost;
integrated security=true; database=pubs"/>
</appSettings>
</configuration>
• Retrieving application settings from a Web.config file
Implementing Dynamic Properties
• Store property values in
Web.config files rather
than in the application's
compiled code
• Allows easy updates
without recompiling the
application
• Enable and configure
through object properties
Lesson: Deploying an ASP.NET Web Application
• Web Application Deployment
• Preparing a Web Application for Deployment
• Sharing Assemblies in the Global Assembly Cache
• Updating Your Web Application
Web Application Deployment
• Copy files locally or FTP files remotely
• Configure the target folder as a virtual directory in IIS
• Copy all necessary files, including the \bin directory and
content
No need to register components
• Create a Web Setup project if a Windows Installer file is
required
Preparing a Web Application for Deployment
1. Build the Web application
2. Do not select unnecessary files
Visual Studio .NET solution files
(.vbproj, .vbproj.webinfo, .csproj, .csproj.webinfo, etc.)
Resource (.resx) files
Code-behind pages (.vb, .cs)
3. Copy or FTP necessary files to the production directory
Sharing Assemblies in the Global Assembly Cache
• The global assembly cache provides storage for assemblies
you need to share
Machine-wide cache for code
Because DLL files are not registered, they are not easily
shared between Web applications
Updating Your Web Application
• Copy or FTP files to update the Web application
Do not need to stop and restart IIS
.dll files can be updated while the site is still running
• Output cache protects existing users
Configuring, Optimizing, and Deploying a
Microsoft ASP.NET Web Application
• Exercise 1: Caching a DataSet by Using the Cache Object
• Exercise 2: Reducing Response Times by Using the Page
Output Cache
• Exercise 3: Partial Page Caching
• Exercise 4: Implementing Dynamic Properties
• Exercise 5: Deploying Your Site
Logon information
Virtual machine 2310C_15
User name Student
Password Pa$$w0rd
Estimated time: xx minutes
Lab Scenario
Logon Page
Login.aspx
Benefits
Coho Home Page Page Header ASPState
Winery Default.aspx Header.ascx
Menu
Registration Component
Register.aspx Class1.vb or Class1.cs Web.
tempdb
config
Life Insurance Retirement Medical Dental
Life.aspx Retirement.aspx Medical.aspx Dental.aspx
Prospectus Doctors User Control XML Web
Lab Web Prospectus.aspx Doctors.aspx namedate.ascx Service
Application dentalService1.asmx
XML
Doctors Dentists
Files
Lab Review
Module Review and Takeaways
Review Questions
• What is the difference between the Cache object and page
output caching?
• What sort of caching would you use to place a DataSet
into cache?
• Which files can you use to configure an ASP.NET Web
application?
• What are the three main steps to deploying an ASP.NET
Web application?
• Why would you consider using dynamic properties to store
the URL to an XML Web service in Web.config?
Course Evaluation
Review for Alpha
• Is there any topic or specific content item in the module
that seemed unclear or unnecessary?
• Is there any content item/related subject area that was
not covered and could be included?
• Did you observe any issues with the technical accuracy of
the content?
• Is the content in the module presented in a manner that
encourages learning? Did the flow of topics seem right?
• Does the lab outline indicate the expected scope of tasks
to be covered? Would you like to suggest any tasks that
could be removed or added?