What’s new in ASP.NET 4.0 - Part I - View State & SEO Improvements

UPDATE dated August 17, 2009

Once I posted this entry, there is a lot of interest that has been shown and few queries as well.  So I thought I need to update this post.

This is only the first post in the series on ASP.NET 4.0 fetaures.  There are lot of ground breaking things and other enhancements that are pretty exciting.

To the folks who asked for "why MS changing dev platform once in 18 months"

There is no change.  there are a few enhancements.  Post .NET 2.0 there have been a lot of additional APIs such as LINQ, Entity Framework etc., which are different ways of data handling.  While core ADO.NET is still valid, these are additional enhancements that can be used at the Developer's / Architect's discretion. 

For the folks you asked about URL Rewriting

There is URL Routing which is much better than URL Rewriting.  We have talked about it, enough in the past .  You can read more about it at http://www.mostlylucid.net/archive/2009/01/25/asp.net-4.0-webform-routing-quick-rsquon-dirty-version.aspx

I will be covering more features in the following post.

Thanks for the inerest

With Visual Studio 2010 Beta 1 and .NET Framework Beta 1 out for some time, this post is due from me for a long time.   ASP.NET 4.0 has many improvements for different set of scenarios such as Webforms, Dynamic Data & AJAX based web development.  There are also a lot of enhancements to the core runtime that powers ASP.NET such as Caching, Session & Request/Response objects.

For this post, we will examine some of the web form enhancements.  There are sure a lot of them and we will examine some of them in the future posts.

Controlling View State using the ViewStateMode Property – Performance Enhancement

One of the most complained thing in ASP.NET Webform is the growing viewstate which becomes a concern for performance.  While earlier you can set the EnableViewState property to true or false, post that, all the controls, by default inherit and even if you set it to enabled at control level, the behaviour was inconsistent.

With ASP.NET 4.0, the ViewStateMode property helps to determine for every control, whether the ViewState should be enabled, disabled or inherited accordingly.  Ex.-

<asp:Panel ID="pnlViewState" runat="server" ViewStateMode="Disabled">
      Disabled: <asp:Label ID="label1" runat="server"  Text="Value set in markup" ViewStateMode="Inherit"  /><br />
           Enabled: <asp:Label ID="label2"  runat="server" Text="Value set in markup" ViewStateMode="Enabled" />
  <hr />
  <asp:button ID="Button1" runat="server"  Text="Postback" />
    </asp:Panel>

In the code-behind

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            label1.Text = "Value set in code behind";
            label2.Text = "Value set in code behind";
        }
    }

When you run the above page, you can find that the intial value for both the labels is set to “Value set in code behind” whereas after clicking on the button (postback), the value of label1 changes to “Value set in markup” whereas the value of label2 remains unchanged.  As you can see, the Panel which holds both these lables has ViewStateMode set to Disabled and label1 is inherting the mode (this is the default if not specified) and label2 has it enabled.  That is the reason label2 maintains viewstate while label1 loses it.

While it is arguably possible using the simple EnableViewState property earlier, it was never consistent.  Considering the fact that in most of our performance sessions, we talk about disabling viewstate and then enabling it at control level while it doesnt work, this ViewStateMode is a welcome architectural change to improve performance.

Page Meta Keyword & Description – Search Engine Optimization feature

Upto Visual Studio 2008, one can set the Title of the page declaratively or through program using Page.Title.  However, as more and more web traffic is happening through search engines, Page’s Title, Keyword and description become more important.  Although the Keyword feature was exploited and hence many search engines today ignore it, Page Description is something still major search engines such as Google, Bing use for identifying and indexing pages based on content.

The new feature in ASP.NET 4.0 allows users to programmatically set the Page Description and Keywords as follows:-

protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.Title = "My ASP.NET Blog";
        this.Page.MetaKeywords = "ASP.NET, Web Development, Blog, ASP.NET Blog";
        this.Page.MetaDescription = "This Blog contains posts related to ASP.NET and Web Development";
    }

The above code appends the following markup

<meta name="keywords" content="ASP.NET, Web Development, Blog, ASP.NET Blog" />

<meta name="description" content="This Blog contains posts related to ASP.NET and Web Development" />

And the way it works is that, if the meta tags are already present in the HTML markup, whatever is set in the code behind  will fill up the “content” part alone if the “name” tag is matching.

Although this looks simple, it is very useful in cases where you want to set these dynamically based on a condition / criteria.  So far, these were set statically in the HTML.  Now with Page Class level access, these can be set dynamically.

There are many more enhancements to Webforms such as Routing improvements, setting ClientID etc., which we will examine in the future posts.

Cheers !!!

posted @ Friday, August 14, 2009 6:15 AM

Print

Comments on this entry:

# re: What’s new in ASP.NET 4.0

Left by Shail at 8/14/2009 7:18 AM
Gravatar
Nice post,
Keep writing more on ASP.Net 4.0. Just one question. What are performance improvements in ASP.Net engine itself. Does they come from improvements in CLR or they come from code improvments.
I am looking for new features, but I am also concerned about the performance.
Thanks

# re: What’s new in ASP.NET 4.0

Left by Textbox at 8/14/2009 8:57 AM
Gravatar
I like the addition of the Page class level access to meta information. Up until now, our inhouse CMS has been simply writing the entire title and meta info to a literal.

# re: What’s new in ASP.NET 4.0

Left by # at 8/14/2009 9:45 AM
Gravatar
Hmm. Theses changes are nice but hardly ground breaking. I'm hoping that further posts reveal something a little be more meaty. :)

# re: What’s new in ASP.NET 4.0

Left by Abdulla AbdelHaq at 8/14/2009 5:33 PM
Gravatar
Really nice new features, especially the new ViewState feature.
Thank you for sharing this with us.

# re: What’s new in ASP.NET 4.0

Left by GIORGIO at 8/14/2009 5:43 PM
Gravatar
ms change develop paradigm every 18 month: for example on data access that i do not know use: ado ado.net linq mvc system.
I'm passing froma asp- asp.net to php.. sorry

# re: What’s new in ASP.NET 4.0

Left by hajan at 8/14/2009 8:23 PM
Gravatar
Nice post. I think we will discover much more new features and advantages of VS.NET 2010 together with ASP.NET 4.0.

# re: What’s new in ASP.NET 4.0

Left by Thanigainathan at 8/14/2009 10:06 PM
Gravatar
Hi,

Nice article. How about MVC framework ? Its going to be next ASP.Net version .

Thaks,
Thani

# re: What’s new in ASP.NET 4.0

Left by Joe at 8/15/2009 1:22 AM
Gravatar
What about PHP 5.3? It looks promising...

# re: What’s new in ASP.NET 4.0

Left by Ashraf at 8/15/2009 3:17 AM
Gravatar
Nice article.

# re: What’s new in ASP.NET 4.0

Left by Rabindra at 8/15/2009 8:36 PM
Gravatar
More article on Asp.net 4.0 , Keep posting so that we can help

# Fix title tag render

Left by Vienīgais at 8/16/2009 3:12 AM
Gravatar
You mentioned Page.Title, so I hope it is right place to complain. Up until now ASP.NET renders title tag with newlines and indent. To fix this I have to put hack (found on asp.net forums) in every Application_Startup, so title renders inline. Is it going to be changed in 4.0?

# re: What’s new in ASP.NET 4.0

Left by elearning at 8/16/2009 6:03 AM
Gravatar
Thanks alot !.

Keep showing us the new enhancements.

# re: What’s new in ASP.NET 4.0

Left by jayesh at 8/16/2009 11:14 AM
Gravatar

asp.net 4.0

it's give smart works on ajax web devlopment.
nice............

# re: What’s new in ASP.NET 4.0

Left by jayesh chauhan at 8/16/2009 11:20 AM
Gravatar
it's about technology that gives better perfomance.

tell me about next version of this,like asp.net 5.0
jayesh_citc@yahoo.com

# re: What’s new in ASP.NET 4.0

Left by Nabil Orfali at 8/16/2009 9:12 PM
Gravatar
Is there any URL rewriting built-in feature ?

# re: What’s new in ASP.NET 4.0

Left by Ziyad at 8/16/2009 11:55 PM
Gravatar
Nabil....wonderful question.
In Microsoft world, you keep lacking the same old features/functionalities. They just add new plug-ins. However, i have heard that there is a feature going to come for URL rewriting, but will be aligned inside the IIS. Hence developers may not be able to benefit this functionality if they host their application in a shared environment.

# re: What’s new in ASP.NET 4.0

Left by ali reza at 8/17/2009 12:35 AM
Gravatar
what will microsoft want to do?
every year with new sotware.where is the final version of asp.net?

# re: What’s new in ASP.NET 4.0

Left by chandradev at 8/17/2009 3:09 AM
Gravatar
It is so nice post.

# re: What’s new in ASP.NET 4.0 - Part I

Left by Nitin at 8/17/2009 10:37 AM
Gravatar
Gr8.. post more info

# re: What’s new in ASP.NET 4.0 - Part I

Left by Nyubi at 8/20/2009 6:00 AM
Gravatar
Cool project, is there more topics about it you psted? Thx for sharing :)

# re: What’s new in ASP.NET 4.0 - Part I

Left by Arun Kumar Prajapati at 8/20/2009 1:43 PM
Gravatar
Nice post dear. Keep posting about new and interesting features of MS Technologies

# re: What’s new in ASP.NET 4.0 - Part I

Left by Gagan at 8/21/2009 2:28 AM
Gravatar
Nice post sir.

# What’s new in ASP.NET 4.0 - Part I

Left by Microsoft Training at 8/21/2009 4:43 AM
Gravatar
Interesting & very informative. Keep updating such info! Software Training Company .

# Application Development Versatilist

Left by Application Development Versatil at 10/14/2009 9:26 PM
Gravatar
Hi
I like this post about asp .net
Thanks for sharing
<a href=“http:// www.synergetics-india.com/”>IT Certification Company India

# re: What’s new in ASP.NET 4.0 - Part I - View State & SEO Improvements

Left by nishithraj at 11/17/2009 9:06 PM
Gravatar
Nice post.

Keep posting in more about ASP.NET 4.0

http://revolution-of-web.blogspot.com

# re: What’s new in ASP.NET 4.0 - Part I - View State & SEO Improvements

Left by rachna at 11/18/2009 7:02 PM
Gravatar
nice plaese send another example related other controls.

# re: What’s new in ASP.NET 4.0 - Part I - View State & SEO Improvements

Left by Christian Louboutin at 11/20/2009 11:42 PM
Gravatar
Anybody can tell me where i can buy the best and the cheapest shoes ,I have to tell him that is christian louboutin shoes ,it will be your right choice.

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345