ASP.NET 4 and Visual Studio 2010 Web Development Overview
Core Services
ASP.NET 4 introduces a number of features that improve core ASP.NET services such as output caching and session-state storage.Web.config File Refactoring
TheWeb.config
file that contains the configuration
for a Web application has grown considerably over the past few releases
of the .NET Framework as new features have been added, such as Ajax,
routing, and integration with IIS 7. This has made it harder to
configure or start new Web applications without a tool like Visual
Studio. In .the NET Framework 4, the major configuration elements have
been moved to the machine.config
file, and applications now inherit these settings. This allows the Web.config
file in ASP.NET 4 applications either to be empty or to contain just
the following lines, which specify for Visual Studio what version of the
framework the application is targeting:<?xml version="1.0"?> <configuration> <system.web> <compilation targetFramework="4.0" /> </system.web> </configuration>
Extensible Output Caching
Since the time that ASP.NET 1.0 was released, output caching has enabled developers to store the generated output of pages, controls, and HTTP responses in memory. On subsequent Web requests, ASP.NET can serve content more quickly by retrieving the generated output from memory instead of regenerating the output from scratch. However, this approach has a limitation — generated content always has to be stored in memory, and on servers that are experiencing heavy traffic, the memory consumed by output caching can compete with memory demands from other portions of a Web application.ASP.NET 4 adds an extensibility point to output caching that enables you to configure one or more custom output-cache providers. Output-cache providers can use any storage mechanism to persist HTML content. This makes it possible to create custom output-cache providers for diverse persistence mechanisms, which can include local or remote disks, cloud storage, and distributed cache engines.
You create a custom output-cache provider as a class that derives from the new System.Web.Caching.OutputCacheProvider type. You can then configure the provider in the
Web.config
file by using the new providers subsection of the outputCache element, as shown in the following example:<caching> <outputCache defaultProvider="AspNetInternalProvider"> <providers> <add name="DiskCache" type="Test.OutputCacheEx.DiskOutputCacheProvider, DiskCacheProvider"/> </providers> </outputCache> </caching>By default in ASP.NET 4, all HTTP responses, rendered pages, and controls use the in-memory output cache, as shown in the previous example, where the defaultProvider attribute is set to AspNetInternalProvider. You can change the default output-cache provider used for a Web application by specifying a different provider name for defaultProvider.
In addition, you can select different output-cache providers per control and per request. The easiest way to choose a different output-cache provider for different Web user controls is to do so declaratively by using the new providerName attribute in a control directive, as shown in the following example:
<%@ OutputCache Duration="60" VaryByParam="None" providerName="DiskCache" %>Specifying a different output cache provider for an HTTP request requires a little more work. Instead of declaratively specifying the provider, you override the new GetOuputCacheProviderName method in the
Global.asax
file to programmatically specify which provider to use for a specific request. The following example shows how to do this.public override string GetOutputCacheProviderName(HttpContext context) { if (context.Request.Path.EndsWith("Advanced.aspx")) return "DiskCache"; else return base.GetOutputCacheProviderName(context); }With the addition of output-cache provider extensibility to ASP.NET 4, you can now pursue more aggressive and more intelligent output-caching strategies for your Web sites. For example, it is now possible to cache the "Top 10" pages of a site in memory, while caching pages that get lower traffic on disk. Alternatively, you can cache every vary-by combination for a rendered page, but use a distributed cache so that the memory consumption is offloaded from front-end Web servers.
n the following folder:
\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers
-
After you define the browser capability, you run the
following command from the Visual Studio Command Prompt in order to
rebuild the browser capabilities assembly and add it to the GAC:
aspnet_regbrowsers.exe -I c
- For an individual application, you create a
.browser
file in the application’sApp_Browsers
folder.
ASP.NET 4 includes a feature referred to as browser capabilities providers. As the name suggests, this lets you build a provider that in turn lets you use your own code to determine browser capabilities.
In practice, developers often do not define custom browser capabilities. Browser files are hard to update, the process for updating them is fairly complicated, and the XML syntax for
.browser
files can be complex to use and define. What would make this process
much easier is if there were a common browser definition syntax, or a
database that contained up-to-date browser definitions, or even a Web
service for such a database. The new browser capabilities providers
feature makes these scenarios possible and practical for third-party
developers.There are two main approaches for using the new ASP.NET 4 browser capabilities provider feature: extending the ASP.NET browser capabilities definition functionality, or totally replacing it. The following sections describe first how to replace the functionality, and then how to extend it.
0 comments:
Post a Comment
mobile here