Resources » .NET programming » ASP.NET/Web Applications

New features of ASP.NET 4.0


Posted Date: 05-Feb-2012  Last Updated:   Category: ASP.NET/Web Applications    
Author: Member Level: Gold    Points: 20


Microsoft has introduced many new features for the both .NET Framework and ASp.NET along with C#. The Dynamic Keyword and Named and Optional Parameters are newly introduced in C#.net 4.0. Below are the newly introduced features in ASP.NET 4.0 version.



1) Output cache extensibility
2) Refactoring Web.config file
3) Session state compression
4) Better control of the ViewState
5) Page.MetaKeyword and Page.MetaDescription propertie.

Output cache extensibility:


As we all know, caching is a coolest feature in ASP.NET. Caching enables you to store the expensive data into the application server memory and it is useful for the later retrieval. For example when you are retrieving the large amount of data from the database, it is tedious to fetch the data from database every time. At this situation we are using the ASP.NET feature caching. It saves the data in the webserver, but this may be slow down the web application and that may cause to another sites which may deploy in the same server.
For the above reason, Microsoft has introduced Output cache extensibility feature along with ASP.NET 4.0 release. The ASP.NET 4.0 developers may extend their caching by using Output cache providers. Now developers needs to create Output cache providers to cache the output data in the in any persistent mechanism like database, clusters, cloud storage, distributed cache engines etc. You should configure the web.config file like as below.

<system.web>
<compilation debug="true" targetFramework="4.0" />
<caching>
<outputCache defaultProvider="mySampleOutputCache">
<providers>
<add name="myCache" type="mySampleCustomCache, exampleCache"/>
</providers>
</outputCache>
</caching>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
</system.web>

A class System.Web.Caching.OutputCacheProvider is useful to create the custom Output cache in your web page. Once you add the below code to your aspx page the output cache will start use the custom one and store in the server which you have specified.

<%@ OutputCache Duration="180" VaryByParam="None" %>

Refactoring Web.config file:


Over the past few years web.config has grown significantly as features of ASP.NET has increased day by day such as routing, Ajax, IIS 7 and version compatibility. It is very difficult to maintain all the features in Visual Studio.
With ASP.NET 4, most of the major elements moved to machine.config file. This has enabled developers to maintain a cleaner, less cluttered, web.config file. The new web.config file is either empty, or includes just the .NET framework version details as shown in the following example.

<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>

Session state compression :


The ASP.NET session state is a mechanism to save the session's state data and maintain across the pages requests. We having different types of Session state mechanism in ASP.NET, those are InProc, OutProc and SqlServer. We can save the sessions data in the state server, but when we have the large amount of data generally needs to be serialized and send to the server, latency time may be increase and application performance may be affected. To avoid this situation .NET introduce the compressionEnabled mechanism to compress the session data and save in the sql server.

<system.web>
<compilation debug="true" targetFramework="4.0" />
<sessionState mode="SQLServer" sqlConnectionString="data source=DBServr;Initial Catalog=PMDB" allowCustomSqlDatabase="true" compressionEnabled="true"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
</system.web>

Better control of the ViewState:



View state is a feature in ASP.NET to maintain the page control state between the subsequent post backs. Asp.NET saves the data for its controls even those data is not required. This data will be save in the browser memory and may degrade the application performance.

ASP.NET 4.0 introduce the property ViewStateMode for each control, by default ViewStateMode is
Disabled and you need to enable if you require the control data in view state.


<asp:TextBox ID="TextBox1" runat="server" ViewStateMode="Enabled"></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" ViewStateMode="Disabled" />


Page.MetaKeyword and Page.MetaDescription properties:


To increase the relevance of page searches we have to add the description and key words in Meta tag html head section, but that will take a time do these activities. In ASP.NET 4.0 they have introduced the Page properties like Page.MetaKeyword and Page.MetaDescription, you need to set these properties in the page load event of a webpage.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication4
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page.MetaDescription = "My sample page description";
Page.MetaKeywords = "My Page";
}
}
}


Did you like this resource? Share it with your friends and show your love!

Responses to "New features of ASP.NET 4.0"
Guest Author: Olavo     20 Feb 2012
I friendlily agree with the whole thing. Took me a while to read but it was well worth it. I'm gonna read through a few other posts on this site and see if wheres anything else that's good like this


Author: Phagu Mahato    06 Oct 2013Member Level: Diamond   Points : 10
There are some more useful feature of ASP.NET 4.0
[1] Extensible Output Caching

You can create a custom output-cache provider as a class that derives from the new System.Web.Caching.OutputCacheProvider type. the sample code is given below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;
using Microsoft.ApplicationServer.Caching;

namespace OutputCacheDemo.OutputCacheProviders
{
public class VelCacheProvider : OutputCacheProvider, IDisposable
{
private DataCache dataCache;
const String OutputCacheName = "OutputCache";
public VelCacheProvider()
{
DataCacheFactory factory = new DataCacheFactory();
this.dataCache = factory.GetCache(OutputCacheName);
}
public override object Add(string key, object entry, DateTime utcExpiry)
{
this.dataCache.Add(key, entry, utcExpiry - DateTime.UtcNow);
return entry;
}
public override object Get(string key)
{
return this.dataCache.Get(key);
}
public override void Remove(string key)
{
this.dataCache.Remove(key);
}
public override void Set(string key, object entry, DateTime utcExpiry)
{
throw new NotImplementedException();
}
public void Dispose()
{
this.dataCache = null;
}
}
}

[2] Implementation strategy:
Using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.Routing;

namespace AppRoutingDemo
{
public class Global : System.Web.HttpApplication
{

void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("ProductsCategory", "products/category/{id}", "~/ProductsCategory.aspx");
}
void Application_Start(object sender, EventArgs e)
{

RegisterRoutes(RouteTable.Routes);
}
}
}



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India