330 likes | 485 Views
Module 15: Configuring, Optimizing, and Deploying a Microsoft ASP.NET Web Application. Overview. Using the Cache Object Using ASP.NET Output Caching Configuring an ASP.NET Web Application Deploying an ASP.NET Web Application. Lesson: Using the Cache Object. What Is the Cache Object?
E N D
Module 15:Configuring, Optimizing, and Deploying a Microsoft ASP.NET Web Application
Overview • Using the Cache Object • Using ASP.NET Output Caching • Configuring an ASP.NET Web Application • Deploying an ASP.NET Web Application
Lesson: Using 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 • Demonstration: Using 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: • Retrieving values from 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); myValue = Cache("myKey") myValue = Cache["myKey"];
Removing Items from the Cache Object • AbsoluteExpiration time • SlidingExpiration time • Dependent on a changed value • Cache item priority DateTime.Now.AddMinutes(5) TimeSpan.FromSeconds(20) AddCacheItemDependency("Variable.Value") CacheItemPriority.High
Demonstration: Using the Cache Object • Run the CacheTest.aspx page without the Cache object enabled • Run the CacheTest.aspx page with the Cache object enabled • Run the CacheTest.aspx page with the Cache object enabled and with a dependency
Lesson: Using ASP.NET Output Caching • Multimedia: Output Caching • Output Cache Types • How to Use Page Output Caches • Demonstration: Page Output Caching • How to Use Fragment Caching
Output Cache Types • Page caching • Page fragment caching as a user control • XML Web service caching
How to Use 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" %>
Demonstration: Page Output Caching • Show how a page that does not cache changes with each refresh • Show how a page that caches does not change with each refresh • Show how changing a parameter can cause a new page to be cached
How to Use Fragment 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 Using Machine.config • Configuring an Application Using Web.config • Understanding Configuration Inheritance • Demonstration: Configuration Inheritance • Practice: Determining Configuration Inheritance • Storing and Retrieving Data in Web.config • Using Dynamic Properties • Demonstration: Using 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 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 using Web.config files
Configuring an Application 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
Understanding Configuration Inheritance • Application-level Web.config file inherits settings from Machine.config file • Settings in Web.config file that conflict override inherited settings • Individual directories may have Web.config files that inherit from—and can override—application-level settings CONFIG Machine.config VirtualDir Web.config SubDir Web.config
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
Practice: Determining Configuration Inheritance • Students will: • Determine the configuration settings for a Web application based on several variables • Time: 5 Minutes
Storing and Retrieving Data in Web.config • Storing application settings in a Web.config file • Retrieving application settings from a Web.config file <configuration> <appSettings> <add key="pubs" value="server=localhost; integrated security=true; database=pubs"/> </appSettings> </configuration> Dim strPubs As String = _ ConfigurationSettings.AppSettings("pubs") AppSettingsReader App = new AppSettingsReader(); string strPubs = (string)App.GetValue("pubs", typeof(string));
Using 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
Demonstration: Using Dynamic Properties • Configure a SqlConnection object to use dynamic properties • Show the newly generated code in the code-behind page • Open Web.config file and show the SqlConnection1.ConnectionString key in the appSettings section
Lesson: Deploying an ASP.NET Web Application • Web Application Deployment • Preparing a Web Application for Deployment • Practice: Selecting Necessary Files • 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
Preparing a Web Application for Deployment • Build the Web application • 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) • Copy or FTP necessary files to the production directory
Practice: Selecting Necessary Files • Students will: • Select the files necessary for a deployment • Time: 5 Minutes
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
Review • Using the Cache Object • Using ASP.NET Output Caching • Configuring an ASP.NET Web Application • Deploying an ASP.NET Web Application
Lab 15: Configuring, Optimizing, and Deploying a Microsoft ASP.NET Web Application Logon Page Login.aspx BenefitsHome PageDefault.aspx CohoWinery Page HeaderHeader.ascx ASPState Menu ComponentClass1.vb or Class1.cs Registration Register.aspx Web.config tempdb Life InsuranceLife.aspx RetirementRetirement.aspx MedicalMedical.aspx DentalDental.aspx XML Web ServicedentalService1.asmx ProspectusProspectus.aspx DoctorsDoctors.aspx User Controlnamedate.ascx Lab Web Application XML Files Doctors Dentists