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
The
Web.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
ASP.NET 4 adds extensibility 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. These storage options 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 OutputCacheProvider type. You can then configure the provider in the Web.config file by using the new providers subsection of the outputCache element .
By default, in ASP.NET 4, all HTTP responses, rendered pages, and controls use the in-memory output cache. The defaultProvider attribute for ASP.NET is AspNetInternalProvider. You can change the default output-cache provider used for a Web application by specifying a different provider name for defaultProvider attribute.
In addition, you can select different output-cache providers for individual control and for individual requests and programmatically specify which provider to use.
<%@ OutputCache Duration="60" VaryByParam="None"
providerName="DiskCache" %>
Auto-Start Web Applications
The feature provides a controlled approach for starting up an application pool, initializing an ASP.NET application, and then accepting HTTP requests. It lets you perform expensive application initialization prior to processing the first HTTP request.Permanently Redirecting a Page
ASP.NET 4 adds a RedirectPermanent helper method that makes it easy to issue HTTP 301 (Moved Permanently) responses, as in the following example:RedirectPermanent("/newpath/foroldcontent.aspx");
Search engines and other user agents that recognize permanent redirects will store the new URL that is associated with the content, which eliminates the unnecessary round trip made by the browser for temporary redirects.
Session State Compression
ASP.NET 4 introduces a new compression option for both kinds of out-of-process session state providers. By using this option, applications that have spare CPU cycles on Web servers can achieve substantial reductions in the size of serialized session state data. This option can be set by using the new compressionEnabled attribute of the sessionState element in the configuration file. When the compressionEnabled configuration option is set to true, ASP.NET compresses (and decompresses) serialized session state by using the .NET Framework GZipStream class.Expanding the Range of Allowable URLs
ASP.NET 4 introduces new options for expanding the size of application URLs. Previous versions of ASP.NET constrained URL path lengths to 260 characters, based on the NTFS file-path limit. In ASP.NET 4, you have the option to increase (or decrease) this limit as appropriate for your applications, using two new attributes of the httpRuntime configuration element
Extensible Request ValidationRequest validation feature has been made extensible so that you can use custom request-validation logic. To extend request validation, you create a class that derives from the new System.Web.Util.RequestValidator class, and you configure the application to use the custom type (in the httpRuntime section of the Web.config file).
Object Caching and Object Caching Extensibility
To make caching available for all applications, the .NET Framework 4 introduces a new assembly, a new namespace, some base types, and a concrete caching implementation. The new System.Runtime.Caching.dll assembly contains a new caching API in the System.Runtime.Caching namespace. The namespace contains two core sets of classes:- Abstract types that provide the foundation for building any type of custom cache implementation.
- A concrete in-memory object cache implementation (the MemoryCache class).
Extensible HTML, URL, and HTTP Header Encoding
In ASP.NET 4, you can create custom encoding routines for the following common text-encoding tasks:
After a custom encoder has been configured, ASP.NET automatically calls the custom encoding implementation whenever public encoding methods of the HttpUtility or HttpServerUtility classes are called. This lets one part of a Web development team create a custom encoder that implements aggressive character encoding, while the rest of the Web development team continues to use the public ASP.NET encoding APIs. By centrally configuring a custom encoder in the httpRuntime element, you are guaranteed that all text-encoding calls from the public ASP.NET encoding APIs are routed through the custom encoder.
- HTML encoding.
- URL encoding.
- HTML attribute encoding.
- Encoding outbound HTTP headers.
After a custom encoder has been configured, ASP.NET automatically calls the custom encoding implementation whenever public encoding methods of the HttpUtility or HttpServerUtility classes are called. This lets one part of a Web development team create a custom encoder that implements aggressive character encoding, while the rest of the Web development team continues to use the public ASP.NET encoding APIs. By centrally configuring a custom encoder in the httpRuntime element, you are guaranteed that all text-encoding calls from the public ASP.NET encoding APIs are routed through the custom encoder.
No comments:
Post a Comment