Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [42]

By Root 5265 0
the folder for a site equipped with ASP.NET 4.

Figure 3-2. The list of .browser files in ASP.NET 4.

In ASP.NET 4, yet another approach is supported to provide browser capabilities—browser providers. In a nutshell, a browser provider is a class you register with the application using the classic provider model, as shown in the following code snippet, or using a line of code in global.asax:

The browser provider usually derives from the system-provided base class HttpCapabilitiesProvider and extends it by overriding some methods.

The Section


The section configures the cache settings for an ASP.NET application. It consists of four child sections: cache, outputCache, outputCacheSettings, and sqlCacheDependency.

The section defines a few application-wide settings that relate to caching. For example, the percentagePhysicalMemoryUsedLimit and privateBytesLimit attributes indicate the maximum size of memory (percentage and bytes) that can be occupied before the cache starts flushing expired items and attempting to reclaim memory. Here’s the schema of the section with default values:

disableExpiration = "false"

privateBytesLimit = "0"

percentagePhysicalMemoryUsedLimit = "89"

privateBytesPollTime = "00:02:00" />

The default time interval between polling for the memory usage is 2 minutes. Note that by setting the disableExpiration attribute you can disable the automatic scavenging of expired cache items—the most defining trait of ASP.NET cache.

The section takes care of output caching. Here is the schema of the section with default values:

enableOutputCache = "true"

enableKernelCacheForVaryByStar = "false"

enableFragmentCache = "true"

sendCacheControlHeader = "true"

omitVaryStar = "false">

If output or fragment caching is disabled in the configuration file, no pages or user controls are cached regardless of the programmatic settings. The sendCacheControlHeader attribute indicates whether the cache-control:private header is sent by the output cache module by default. Similarly, the omitVaryStar attribute enables or disables sending an HTTP Vary: * header in the response. The enableKernelCacheForVaryByStar attribute controls whether kernel caching is enabled or not. You should note that kernel caching is supported only for compressed responses. This means that regardless of the attribute’s value, kernel caching won’t work any time the client requests an uncompressed response.

The defaultProvider attribute indicates the component that takes care of storing and serving the cached output. The default provider is based on the same code that powered output caching in earlier versions of ASP.NET. The store is the in-memory cache. By writing your own provider, you can change the storage of the output cache. Note that the AspNetInternalProvider provider name doesn’t really match any class in the system.web assembly. It is simply a moniker that instructs the system to go with the built-in logic that worked for any previous versions of ASP.NET. The framework offers a new abstract class—OutputCacheProvider—that represents your starting point on the way to building custom output cache providers.

The section contains groups of cache settings that can be applied to pages through the @OutputCache directive. The section contains only one child section, named . An output cache profile is simply a way of referencing multiple settings with a single name. Here’s an example:

duration="60"

varyByCustom="browser" />

In the example, the ServerOnly profile defines a cache duration of 60 seconds and stores different versions of the page based on browser type. Here is the schema of :

Return Main Page Previous Page Next Page

®Online Book Reader