Click here to Skip to main content
11,629,614 members (55,101 online)
Click here to Skip to main content

ASP.Net 4.0 New Features

, 9 Jul 2011 CPOL 32.3K 11
Rate this:
Please Sign up or sign in to vote.
ViewStateMode – ViewState for Individual Controls ASP.Net 4.0 allows view state in a page to be more controllable from page to its child controls level. That is, view state of a control can be enabled or disabled irrespective of its parent control’s view state. Even if view state of a page is disabl

ViewStateMode – ViewState for Individual Controls

ASP.Net 4.0 allows view state in a page to be more controllable from page to its child controls level. That is, view state of a control can be enabled or disabled irrespective of its parent control’s view state. Even if view state of a page is disabled, controls of the page can have their own view state individually enabled or disabled or even inherited from the page’s view state mode property. This property if utilized properly can certainly boost performance of a page.

For example, we can individually enable or disable user control’s view state in a page.

ViewStateMode

By default, ViewStateMode is enabled for a page object, while controls have inherit mode.

Page.MetaKeywords and Page.MetaDescription – SEO Optimization Feature ASP.Net 4.0 has come up with these two properties that will help developers add meta tags for keywords and description in the aspx pages in easier fashion. Web Search Engines really need these two meta tags for search indexing of any pages. These two properties can be used in a page in various ways. Inside <head> tag or in the code behind or even at <%@Page%> directive level.

However, setting meta keywords or description in code behind will be more useful when we have to add keywords and descriptions dynamically from source like database.

MetaKeyWords is used to store few useful keywords that will briefly highlight important information of a page by tags. From SEO perspective, meta keywords should contain keywords separated by spaces.

MetaDescription is used to add page description in short that will help Search Engines to quickly describe about the page links in search pages.

Prior to ASP.Net 4.0, we have to add meta tags using HtmlMeta control (public class HtmlMeta : HtmlControl) adding into page header as:

protected void Page_Load(object sender, EventArgs e)
{
//
HtmlMeta metakey = new HtmlMeta();
metakey.Name = “keywords”;
metakey.Content = “ASP.Net 2.0 3.5″;
HtmlMeta metadesc = new HtmlMeta();
metadesc.Name = “description”;
metadesc.Content = “ASP.Net 2.0 3.5 Page Description…”;
//Add to page header
Page.Header.Controls.Add(metakey);
Page.Header.Controls.Add(metadesc);
}

In ASP.Net 4.0, we can add in many ways.

protected void Page_Load(object sender, EventArgs e)
{
//Adding Page meta tags information
this.Page.MetaKeywords = “ASP.Net 4.0 SEO Meta Tag”;
this.Page.MetaDescription = “Serializing and Deserializing Thoughts..”;
}

Or,

<head runat="”server”">
<title>Feature: ViewStateMode</title>
<meta name=”keywords” content =”ASP.Net 4.0 ViewStateMode”/>
<meta name=”description” content=”ViewStateMode feature in ASP.Net 4.0″ />
</head>

Or inside Page directive,

MetaDescription

Response.RedirectPermanent – Search Engine Friendly Webpage Redirection

In classic ASP or ASP.Net earlier than 4.0, we used to redirect to new pages or links by setting Response.StatusCode to 301 before calling Response.AddHeader method. Now ASP.Net 4.0 has provided Response.RedirectPermanent method to redirect to new pages or links with StatusCode of 301 implicitly set. Search Engines use this 301 code to understand permanent redirection from old pages links.

For example, Classic ASP method:

<%@ Language="VBScript" %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,”http://www.new-page-url.com/”
%>

ASP.Net method prior to 4.0:

<script runat="”server”">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(“Location”,”http://www.new-page-url.com”);
}
</script>

ASP.Net 4.0 method:

Response.RedirectPermanent(“http://www.new-page-url.com “);

Web.Config Refactoring – Custom HttpHandlers and HttpModules

Web.config now looks cleaner as most of the settings are controlled from machine.config file as ASP.Net 4.0 is all set to benefit from IIS 7 and IIS 7.5 features. When IIS is set to use .Net 4.0 and Integrated Pipeline mode, <compilation> element holds .Net version attribute. And the traditional <httpHandlers> and <httpModules> section is now shifted out of <system.web> and added inside new section <system.webserver>. All the custom handlers are added inside <handlers>, and all the modules inside <modules> section.

<system.webServer>
<!– Add the module for Integrated mode applications –>
<modules runAllManagedModulesForAllRequests=”true”>
<add name=”MyModule” type=”WebAppModule.MyCustomModule, WebAppModule” />
</modules>
<!– Add the handler for Integrated mode applications –>
<handlers>
<add name=”MyHandler” path=”svrtime.tm” verb=”GET” 
    type=”WebAppModule.MyCustomHandler, WebAppModule” preCondition=”integratedMode” />
</handlers>
</system.webServer>

Also,

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

Interesting point is, when we add custom handlers and modules this way, we do not have to manually configure handlers and modules in IIS again. IIS will automatically refresh itself.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dinesh K Mandal
Technical Lead Imfinity India Pte Ltd, Noida (Excelsoft Company)
India India
http://www.imfinity.com/

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150723.1 | Last Updated 10 Jul 2011
Article Copyright 2010 by Dinesh K Mandal
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid