• Now Online : 55
  • admin@codemyne.net


The .Net Framework new version 4 includes various enhancements in ASP.NET in target areas. This helps good programming experience to the developers for web development.

Enhancements made in the following sections :

  1. ASP.NET Core Services
  2. ASP.NET Web Forms
  4. Dynamic Data
  5. ASP.NET Chart Control
  6. Visual Web Developer Enhancements
  7. Web Application Deployment with Visual Studio 2010
  8. Enhancements to ASP.NET Multi-Targeting

ASP.NET Core Services

ASP.NET 4 introduces many features in ASP.NET services such as output caching and session state storage.

Web.config File Refactoring

In the .Net Framework 4 many elements from web.config file have been moved to machine.config file. And the application will inherit these settings.

This allows the web.config file in .Net Framework 4 to specify only which version of the Framework, the application is targetting.

<?xml version="1.0"?> 
    <compilation targetFramework="4" /> 
Extensible Output Caching

Caching provides a powerful way to improve the performance of web applications, by storing 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 some limitations that generated content always has to be stored in memory. On servers that experience heavy traffic, the memory requirements for output caching can compete with memory requirements for other parts of a Web application.

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.

A custom output-cache provider can be created as a class that derives from the OutputCacheProvider type. Then you can 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.

Declaratively by using the new providerName attribute in a page or control directive is as shown below:

<%@ OutputCache Duration="60" VaryByParam="None" 
    providerName="DiskCache" %>
Auto-Start Web Applications

Some web applications need to process large amount of data, before they serving the first request. For this, developers use "Application_Start" event handler within the Global.asax file of an application.

In ASP.NET 4 a new feature called 'Auto-Start' is introduced. This feature is only availble when ASP.NET 4 runs on IIS 7.5 on Windows Server 2008 R2. The auto-start feature provides a controlled approach for starting up an application pool, initializing an ASP.NET application, and then accepting HTTP requests.

To use this feature, IIS 7.5 'Application-Pool' worker process is to be configured which runs the application automatically when the web-server first loads. For this open applicationHost.config file from 'C:\Windows\System32\inetsrv\config\applicationHost.config' path. Add the attributes as shown below for appropriate application pools entry.

    <add name="MyApplicationPool" startMode="AlwaysRunning" />

Because a single application pool can contain multiple applications, specify individual applications to be automatically started by using the following configuration in the applicationHost.config file:

    <site name="MySite" id="1">
        <application path="/"
            serviceAutoStartProvider="PrewarmMyCache" >
            <!-- Additional content -->
<!-- Additional content -->
   <add name="PrewarmMyCache"
    type="MyNamespace.CustomInitialization, MyLibrary" />

For each application that is marked for auto-start, IIS7.5 sends a request to ASP.NET 4 to start the application in a state during which the application temporarily does not accept HTTP requests. When it is in this state, ASP.NET instantiates the type defined by the serviceAutoStartProvider attribute and calls into its public entry point.

A managed auto-start type with the necessary entry point can be created by implementing the IProcessHostPreloadClient interface, as shown below:

public class CustomInitialization : System.Web.Hosting.IProcessHostPreloadClient
    public void Preload(string[] parameters)
        // Perform initialization.
Permanently Redirecting a Page

In ASP.NET, developers have traditionally handled requests to old URLs by using the Redirect method to forward a request to the new URL. However, the Redirect method issues an HTTP 302 (Found) response (which is used for a temporary redirect). This results in an extra HTTP round trip.

ASP.NET 4 adds a RedirectPermanent helper method that makes it easy to issue HTTP 301 (Moved Permanently) responses as shown below example:


Search engines and other user agents that recognize permanent redirects will store the new URL that is associated with the content. This eliminates the unnecessary round trip made by the browser for temporary redirects.

Shrinking Session State

Asp.Net provides two default option to store session state for a web farm. The first one is a session state provider that invokes an out-of-process session state server. The next one is a session state provider that stores data in a Microsoft SQL Server database.

This session state is to be serialized before it sent to remote storage. Because both options store state information outside a Web application's worker process.

ASP.NET 4 introduces a new compression option for both kinds of out-of-process session-state providers. The class used for serialized session state is System.IO.Compression.GZipStream class. The following

sqlConnectionString="data source=dbserver;Initial Catalog=aspnetstate"
compressionEnabled="true" />
Expanding the Range of Allowable URLs

The URL length is limited to 256 characters in previous versions of ASP.NET, based on the NTFS file-path limit

In ASP.NET 4 an option is given increase or decrease the length of URL as shown below:
< httpRuntime maxRequestPathLength="260" maxQueryStringLength="2048" />

ASP.NET 4 also enables to configure the characters that are used by the URL character check. When ASP.NET finds an invalid character in the path portion of a URL, it rejects the request and issues an HTTP 400 error.

<httpRuntime requestPathInvalidChars="&lt;,&gt;,*,%,&amp;,:,\,?" />
Object Caching and Object Caching Extensibility

The cache implementation has been popular in web applications. It can't be used in Win-Forms or WPF applications. 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 System.Runtime.Caching.MemoryCache class).

In next article we will see about What is New in ASP.NET 4 Web Forms.

Comments/Suggestions are invited. Happy coding......!

Comments Post a Comment