ViewStateMode – ViewState for Individual Controls
ASP.NET 4.0 allows viewstate 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 viewstate 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.
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 an 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)
{
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:
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″ />
The 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.