New features in ASP.NET 4.0

author-image
CIOL Bureau
Updated On
New Update

BANGALORE, INDIA: Microsoft's ASP.NET is one of the most popular web application development technologies ever. ASP.NET is a language-neutral, interoperable server side technology that runs on top of the managed environment of Microsoft .NET's CLR and within the context of a web server like IIS and allows creation, execution, and deployment of scalable Web Applications and services seamlessly. ASP.NET 4.0 has introduced a lot of new features and enhancements.

Advertisment

This article presents these new features and enhancements in ASP.NET 4.0 in a lucid language with code snippets wherever appropriate. Note that the features and enhancements to ASP.NET 4.0 discussed in this article apply to Visual Studio 2010 Beta 2 or later.

The Pre-Requisites

It should be noted that ASP.NET 4.0 ships with Visual Studio 2010. To work with ASP.NET 4.0, you should have Visual Studio 2010 installed in your system. As of this writing, Visual Studio 2010 Beta 2 has been released. You can download a copy of Visual Studio 2010 Beta 2 from this link: http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx

So, what’s new?

The new features and enhancements in ASP.NET 4.0 include:

State Management Improvements – These include improvements to ViewState, Session and Cache
Enhancements to ASP.NET Data Presentation Controls
Enhanced Support for Performance Monitoring
Enhanced control over ControlIDs of Controls
Support for Routing
Search Engine Optimization Enhancements
Simplification of Web.Config file

State Management Improvements

In ASP.NET 4.0, there has been marked improvements in Cache, Session and ViewState. The ASP.NET 4.0 Cache API now allows you to store data in any of the following cache storages:

Disk-based output caches – This is used to store cache data in disk
Custom object caches – This is used to store cache data using custom cache providers
Distributed object caches – This is used to store cache data in a separate server
Cloud-based object caches – This is used to store cache data in cloud databases

Now you can use ASP.NET 4.0 Cache API to design and implement your custom cache storage provider too. You can also configure your custom cache provider easily in your application's web.config file. Here's an example:

Advertisment


type="MyDiskCacheProvider.OutputCacheEx.DiskOutputCacheProvider,MyDiskCacheProvider"/>

There has also been a marked improvement in ViewState in ASP.NET 4.0. You can now use the ViewStateMode property - a new property introduced for all controls in ASP.NET 4.0, to determine whether or not ViewState should be enabled for a particular control in your webform. This gives your better control and flexibility on the ViewState as the EnableViewState property introduced in the earlier versions of ASP.NET resulted in inconsistent behavior of the ViewState.

 

Enhancements to ASP.NET Data Presentation Controls

In ASP.NET 4.0, the LayoutTemplate of the ListView control is optional. You can now use the ItemTemplate of the ListView control to display and manage your data. Here is an example:

ClientIDMode="Predictable">

Customer Code:

Customer Name:


Another improvement in ASP.NET 4.0 is the introduction of a new property called RepeatLayout in the RadioButtonList and CheckBoxList controls.

Enhanced Support for Performance Monitoring

You can turn on application resource monitoring feature for your applications by using the following configuration in the aspnet.config file:





It should be noted that when the appDomainResourceMonitoring feature is enabled in your application, two new performance counters are distinctly visible in the "ASP.NET Applications Performance" category. These include the following:

Advertisment

1. % Managed Processor Time
2.Managed Memory Used
Enhanced control over ControlIDs of Controls
With ASP.NET 4.0, you can have better control over the controlIDs of your data controls in the web page. ASP.NET 4.0 introduces a new property called ClientIDMode for each an every control. This property can have any one of the following possible values:

  • AutoID
  • Inherit
  • Static
  • Predictable

Note that you can set the ClientIDMode property at the page, application and even at the control levels. The following code snippet illustrates how you can set the ClientIDMode at the application level:

The following code snippet illustrates how you can set the ClientIDMode for a TextBox control in your markup code.

Advertisment

To set the ClientIDMode property at the control level, you can use the foollowing syntax:

And, here is how you can set the ClientIDMode property at the page level:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"  ClientIDMode="Predictable" %>

Advertisment

 

Support for Routing

Routing was initially introduced in ASP.NET MVC Framework. With ASP.NET 4.0, Routing has been made a feature of ASP.NET as well. You can use Routing to map specific resources using user friendly URLs. Note that support for Webform Routing in ASP.NET 4.0 is provided by the System.Web.Routing namespace.

Search Engine Optimization Enhancements

In ASP.NET 4.0 there are two new properties in your Page class called Keywords and Description. You can use them to optimize searches.

The following code snippet illustrates how you can set these properties using C# code in the code behind file for your web form:

public partial class TestWebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
 { 
   Page.Keywords = "ASP.NET 4.0 Programming by Joydip Kanjilal";    
   Page.Description = "PC Quest";  
 }
}

It is also possible to achieve the same using markup code. Here is an example:



ASP.NET 4.0 Programming by Joydip Kanjilal
     

Simplification of Web.Config file

The web.config file in ASP.NET 4.0 is much simplified. Most of the configuration elements have now been moved to the machine.config file. This results in reduced size of the web.config file. You can now specify the framework that your application is designed to be targeted at. To do this, you can simply specify the following in your application’s web.config file:


  
   
  

 

Summary

This article has had a look at the new features and enhancements in ASP.NET 4.0. It was an attempt to provide you a head start to mastering the new features and enhancements in ASP.NET 4.0 so as to leverage them to build scalable, robust, high-performance web applications seamlessly. You can know more on the new features and enhancements in ASP.NET 4.0 from my latest book, titled, "ASP.NET 4.0 Programming" (McGraw-Hill Osborne Media). Here is the link to the book at Amazon: http://www.amazon.com/ASP-NET-4-0-Programming-Joydip-Kanjilal/dp/0071604103

Author Biography

Joydip Kanjilal is a Microsoft Most Valuable Professional in ASP.NET. He has over 12 years of industry experience in IT with more than 6 years in Microsoft .NET and its related technologies. He was selected as MSDN Featured Developer of the Fortnight (MSDN) a number of times and also as Community Credit Winner at www.community-credit.com several times. Joydip has authored the following books:-

ASP.NET 4.0 Programming (Mc-Graw Hill Publishing)
Entity Framework Tutorial (Packt Publishing)
Pro Sync Framework (APRESS)
Sams Teach Yourself ASP.NET Ajax in 24 Hours (Sams Publishing)
ASP.NET Data Presentation Controls Essentials (Packt Publishing)

Joydip has also authored more than 200 articles for some of the most reputable sites like, www.asptoday.com, www.devx.com, www.aspalliance.com, www.aspnetpro.com, www.sql-server-performance.com, www.sswug.com, etc. A lot of these articles have been selected at www.asp.net - Microsoft’s Official Site on ASP.NET. Joydip is currently working as an independent software consultant and author. He has years of experience in designing and architecting solutions for various domains. His technical strengths include, C, C++, VC++, Java, C#, Microsoft .NET, Ajax, WCF, REST, SOA, Design Patterns, SQL Server, Operating Systems and Computer Architecture.

Blog: http://aspadvice.com/blogs/joydip
e-MailID: joydipkanjilal@yahoo.com

tech-news