<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7328185059134214054</id><updated>2012-01-14T06:54:11.509-08:00</updated><category term='mobile'/><category term='Sorting'/><category term='Performance and Scalability'/><category term='URL Rewriting'/><category term='CruiseControl.net'/><category term='SQL Server'/><category term='AJAX'/><category term='VS 2010'/><category term='String handling'/><category term='VS.net 2008'/><category term='Security'/><category term='MS office'/><category term='User Controls'/><category term='Debugger'/><category term='FTP'/><category term='ASP.net Authentication'/><category term='Web controls'/><category term='Web Parts'/><category term='WWF'/><category term='News'/><category term='Email integration'/><category term='ASP.net 4.0 new features'/><category term='.net Architecture'/><category term='ASP.net Overview'/><category term='Threading'/><category term='LINQ'/><category term='.Net 4.0'/><category term='ADO.net'/><category term='jQuery'/><category term='Charts Graphs and Images'/><category term='Masterpage'/><category term='Javascript'/><category term='Smart Client'/><category term='Date; SQL Server'/><category term='Web Services'/><category term='GridView'/><category term='.Net Remoting'/><category term='ASP.net code examples'/><category term='ASP.net deployement'/><category term='SQL Server Reporting'/><category term='.NET Framework'/><category term='Caching'/><category term='MVC Video'/><category term='Web crawler'/><category term='Compression'/><category term='SharePoint Services'/><category term='C#'/><category term='Payment Gateway'/><category term='socket'/><category term='WCF'/><category term='Catharsis'/><category term='encrypt and decrypt'/><category term='Converter'/><category term='ViewState'/><category term='Upload'/><category term='WPF'/><category term='ASP.net'/><category term='C# Winform'/><category term='MVC (Model View Controller)'/><category term='Silverlight'/><category term='Impersonation'/><title type='text'>Asp.net and c#</title><subtitle type='html'>This is for improving knowledge of dot net technology, I have posted some articles related to Ajax, C sharp, vb.net, threading, linq, webservices, jQuery, Caching, .net Architecture, .Net Remoting, ADO.net, Authentication, ASP.net Overview, Debugger, Email integration, FTP, Payment Gateway, Performance and Scalability, Security, VS.net 2008, Web controls, Web Parts, WCF, WPF and SQL serve</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default?start-index=101&amp;max-results=100'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>366</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-4944530809928302871</id><published>2011-09-07T11:46:00.000-07:00</published><updated>2011-09-07T11:49:46.478-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.net'/><category scheme='http://www.blogger.com/atom/ns#' term='URL Rewriting'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>URL Rewriting in ASP.NET using global.asax and web.config</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: x-small;"&gt;URL rewriting is very important for search engines like google, yahoo, etc. as we know website getting most of the traffic from search&amp;nbsp;engines.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: 13px;"&gt;Here I am explaining 2 way to rewrite URL in asp.net.&lt;/span&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;b&gt;URL rewrining using web.config and&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: 13px;"&gt;&lt;b&gt;URL rewriting using global.asax&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;URL rewrining using web.config:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: 13px;"&gt;URL rewriting in web.config is only use for small number of pages. Here you have to rewrite every page manually in web.config. I am writing sample code for 4 urls.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;xml&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;version&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;1.0&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;?&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;configuration&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;urlMappings&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;enabled&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;true&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;add&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;url&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;~/About-company.aspx&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;mappedUrl&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;~/index.aspx?id=1&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;add&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;url&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;~/About-products.aspx&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;mappedUrl&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;~/index.aspx?id=2&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;add&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;url&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;~/Contact-us.aspx&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;mappedUrl&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;~/index.aspx?id=3&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;add&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;url&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;~/our-team.aspx&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red; font-family: Arial, sans-serif; font-size: 10pt;"&gt;mappedUrl&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;~/index.aspx?id=4&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;urlMappings&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;. . .&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;configuration&lt;/span&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-top: 15.0pt; mso-margin-bottom-alt: auto; mso-outline-level: 1;"&gt;&lt;b&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;URL rewriting using global.aspx:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;This very simple way and very use full. In this way we can rewrite N number of pages and there is no need extra server configuration. Only you have to use &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;b&gt;Application_BeginRequest&lt;/b&gt; event. Inside this event use &lt;b&gt;Context.RewritePath&lt;/b&gt; method to set which URL will execute internally in code behind. Here is the code:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-top: 15.0pt; mso-margin-bottom-alt: auto; mso-outline-level: 1;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-top: 15.0pt; mso-margin-bottom-alt: auto; mso-outline-level: 1;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;Application_BeginRequest(&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;sender,&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: #2b91af; font-family: Arial, sans-serif; font-size: 10pt;"&gt;EventArgs&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;e)&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: green; font-family: Arial, sans-serif; font-size: 10pt;"&gt;// Get the current path&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;CurrentURL_Path = Request.Path.ToLower();&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt;"&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;(CurrentURL_Path.StartsWith(&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt;"&gt;"/news/"&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;))&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CurrentURL_Path = CurrentURL_Path.Trim(&lt;/span&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;"/"&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: blue; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;NewsID = CurrentPath.Substring(CurrentPath.IndexOf(&lt;/span&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;"/"&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;));&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: #2b91af; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;HttpContext&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;MyContext =&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: #2b91af; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;HttpContext&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;.Current;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyContext.RewritePath(&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: #a31515; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;"/news-show.aspx?News="&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;+ &amp;nbsp;NewsID);&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;&lt;span class="apple-style-span"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color: black; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"&gt;&lt;span class="apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="line-height: 14px;"&gt;In next article i will write about URL rewriting using HttpModule.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-4944530809928302871?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/4944530809928302871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=4944530809928302871' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/4944530809928302871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/4944530809928302871'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/09/url-rewriting-in-aspnet-using.html' title='URL Rewriting in ASP.NET using global.asax and web.config'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-289191313603450884</id><published>2011-07-27T05:46:00.000-07:00</published><updated>2011-07-27T05:46:29.657-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC Video'/><title type='text'>Url Routing MVC TUTORIAL</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;This tutorial covers an introduction to the MVC pattern using Visual Basic. It also includes a brief overview of the URL routing assumptions that are a foundation to the implementation of the pattern. A sample application is created to demonstrate the fundamentals of this new web-application model. Implementing business rules and testing is also covered. Finally, the use of two alternative view engines, Silverlight and XML Literals, is coverd.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;iframe allowfullscreen="" frameborder="0" height="349" src="http://www.youtube.com/embed/sRNGSY8us00" width="425"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-289191313603450884?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/289191313603450884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=289191313603450884' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/289191313603450884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/289191313603450884'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/07/url-routing-mvc-tutorial.html' title='Url Routing MVC TUTORIAL'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://img.youtube.com/vi/sRNGSY8us00/default.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-3086905284488513454</id><published>2011-07-27T05:32:00.000-07:00</published><updated>2011-07-27T05:32:52.465-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC Video'/><title type='text'>What is ASP.NET MVC? 80 minute technical video for developers, building NerdDinner</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;iframe allowfullscreen="" frameborder="0" height="349" src="http://www.youtube.com/embed/trpZuuTICWM" width="425"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-3086905284488513454?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/3086905284488513454/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=3086905284488513454' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/3086905284488513454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/3086905284488513454'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/07/what-is-aspnet-mvc-80-minute-technical.html' title='What is ASP.NET MVC? 80 minute technical video for developers, building NerdDinner'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://img.youtube.com/vi/trpZuuTICWM/default.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-5213052163674332379</id><published>2011-06-21T02:06:00.000-07:00</published><updated>2011-06-21T02:06:28.535-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC (Model View Controller)'/><title type='text'>Overview of ASP.NET MVC Routing</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this tutorial, we introduce an important feature of all ASP.NET applications ASP.NET MVC Routing call. The ASP.NET routing module is responsible for assigning incoming requests particular browser MVC controller actions. At the end of this tutorial, you will understand how the standard routing table maps requests to controller actions. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Using the default route table &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;When you create a new ASP.NET MVC, the application is configured to use ASP.NET Routing. ASP.NET routing is configured in two places. &lt;br /&gt;&lt;br /&gt;First, ASP.NET routing is enabled on the file from the Web application configuration (Web.config file). There are four sections in the configuration file that are relevant for routing: the system.web section. httpModules, section system.web.httpHandlers, system.webserver.modules section and section system.webserver.handlers. Be careful not to delete these sections, because without these sections routing no longer work. &lt;br /&gt;&lt;br /&gt;Second, and most importantly, a routing table is created in the application's Global.asax file. The Global.asax file is a special file that contains event handlers for the events of the life cycle of the ASP.NET application. The routing table is created during the application start event. &lt;br /&gt;&lt;br /&gt;The file in Listing 1 contains the default Global.asax file for an ASP.NET MVC application.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1 - Global.asax.cs&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Mvc;&lt;br /&gt;using System.Web.Routing;&lt;br /&gt;&lt;br /&gt;namespace MvcApplication1&lt;br /&gt;{&lt;br /&gt;// Note: For instructions on enabling IIS6 or IIS7 classic mode, &lt;br /&gt;// visit http://go.microsoft.com/?LinkId=9394801&lt;br /&gt;&lt;br /&gt;public class MvcApplication : System.Web.HttpApplication&lt;br /&gt;{&lt;br /&gt;public static void RegisterRoutes(RouteCollection routes)&lt;br /&gt;{&lt;br /&gt;routes.IgnoreRoute("{resource}.axd/{*pathInfo}");&lt;br /&gt;&lt;br /&gt;routes.MapRoute(&lt;br /&gt;"Default",                                              // Route name&lt;br /&gt;"{controller}/{action}/{id}",                           // URL with parameters&lt;br /&gt;new { controller = "Home", action = "Index", id = "" }  // Parameter defaults&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void Application_Start()&lt;br /&gt;{&lt;br /&gt;RegisterRoutes(RouteTable.Routes);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When an MVC application first starts, the method Application_Start () is called. This method in turn calls the RegisterRoutes () method. The RegisterRoutes () creates the routing table. &lt;br /&gt;&lt;br /&gt;The routing table contains a single default route (default name). The default route maps the first part of a URL for a driver name, the second segment of the URL of a controller action, and the third segment with a parameter named id. &lt;br /&gt;&lt;br /&gt;Imagine you enter the following URL into the address bar of your browser: &lt;br /&gt;&lt;br /&gt;/ Home/Index/3 &lt;br /&gt;&lt;br /&gt;Maps of the default route this URL for the following parameters: &lt;br /&gt;&lt;br /&gt;controller = Home &lt;br /&gt;&lt;br /&gt;action = index &lt;br /&gt;&lt;br /&gt;id = 3 &lt;br /&gt;&lt;br /&gt;When you request the URL / Home/Index/3, the code runs as follows: &lt;br /&gt;&lt;br /&gt;HomeController.Index (3) &lt;br /&gt;&lt;br /&gt;The default route includes defaults for all three parameters. Failure to provide a driver, then the default parameters of the controller to the brokerage. Failure to provide an action, the default parameters of action for the value index. Finally, failure to provide an identifier, the id parameter defaults to an empty string. &lt;br /&gt;&lt;br /&gt;Here are some examples of how the default route maps URLs to controller actions. Imagine you enter the following URL into the address bar of your browser: &lt;br /&gt;&lt;br /&gt;/ Home &lt;br /&gt;&lt;br /&gt;Because the default the default path, entering this URL will cause the index () class in Schedule 2 HomeController called.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 2 - HomeController.cs&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;using System.Web.Mvc;&lt;br /&gt;&lt;br /&gt;namespace MvcApplication1.Controllers&lt;br /&gt;{&lt;br /&gt;[HandleError]&lt;br /&gt;public class HomeController : Controller&lt;br /&gt;{&lt;br /&gt;public ActionResult Index(string id)&lt;br /&gt;{&lt;br /&gt;return View();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In Listing 2, the class includes a method called HomeController Index () that accepts one parameter named ID. The URL / Home causes the index () to call an empty string as the parameter id. &lt;br /&gt;&lt;br /&gt;Due to the way the MVC framework invokes the actions of the driver, the URL / Home also matches the index () HomeController class in Listing 3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Listing 3 - HomeController.cs (Index action with no parameter)&lt;br /&gt;&lt;br /&gt;using System.Web.Mvc;&lt;br /&gt;&lt;br /&gt;namespace MvcApplication1.Controllers&lt;br /&gt;{&lt;br /&gt;[HandleError]&lt;br /&gt;public class HomeController : Controller&lt;br /&gt;{&lt;br /&gt;public ActionResult Index()&lt;br /&gt;{&lt;br /&gt;return View();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The index () method in Listing 3 does not accept any parameters. The URL / Home will make the index () to be called. The URL / Home/Index/3 also invokes this method (the ID is ignored). &lt;br /&gt;&lt;br /&gt;The URL / Home also matches the index () HomeController class in Listing 4.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 4 - HomeController.cs (Index action with nullable parameter)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;using System.Web.Mvc;&lt;br /&gt;&lt;br /&gt;namespace MvcApplication1.Controllers&lt;br /&gt;{&lt;br /&gt;[HandleError]&lt;br /&gt;public class HomeController : Controller&lt;br /&gt;{&lt;br /&gt;public ActionResult Index(int? id)&lt;br /&gt;{&lt;br /&gt;return View();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In Listing 4, the method index () has an integer parameter. Because the parameter is nullable (can be set to zero), the index () can be called without causing an error. &lt;br /&gt;&lt;br /&gt;Finally, invoking the index () method in Listing 5 to the URL / Home causes an exception as the parameter identification is not a parameter accepts null values. If you try to invoke the method index () then the error is show.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The URL / Home/Index/3 other hand, works very well with the controller action index List 5. Application / Home/Index/3 makes the method index () is called with a parameter ID that has the value 3. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Summary &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The aim of this tutorial is to provide a brief introduction to ASP.NET Routing. We examined the routing table by default you get with a new ASP.NET MVC. He has learned default route maps URLs to controller actions.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-5213052163674332379?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/5213052163674332379/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=5213052163674332379' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/5213052163674332379'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/5213052163674332379'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/06/overview-of-aspnet-mvc-routing.html' title='Overview of ASP.NET MVC Routing'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-3938969734380072409</id><published>2011-05-26T23:24:00.000-07:00</published><updated>2011-05-28T05:36:39.987-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><title type='text'>Seven Tips and Tricks Programming WPF</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The Internet has much to offer in any topic and there is much to learn, but where to start? I realized many years ago, when I got intrigued by the Windows Presentation Foundation (WPF), short write-ups that help you acquire additional knowledge, which when combined can provide solutions to the bigger picture. This article provides a list of tips I learned a year ago, while scanning for simple solutions to big problems.&amp;nbsp;&lt;/span&gt;javascript:void(0)&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Use the list Visibility.Collapsed vs Visibility.Hidden&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The collapsed value ensures that the element is not involved in the design and gives you a zero height and width. The latter causes the element to continue to participate in the design.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Reduce CPU consumption for animations to WPF&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;As you know, WPF animations are based on 60 frames per second. You can reduce this to a lower optimal rate, resulting in less CPU usage. Use the timeline. DesiredFrameRateProperty to change the default, set to a lower value as 15, and then changes according to the smoothness you want.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="alert"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Timeline.DesiredFrameRateProperty.OverrideMetadata(&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; typeof(Timeline),&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new FrameworkPropertyMetadata { DefaultValue = 15 }&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Default of Culture of the application for the Culture of the client machine&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;WPF elements expose a property of language that can be used to map language as any culture. When this property is applied to a window, applies to all items it contains. See the sample code that applies the language of contemporary culture. The start function in the application class is an ideal place to implement this change through the application.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="alert"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;protected override void OnStartup(StartupEventArgs e)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag)));&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;base.OnStartup(e);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;}&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Use StaticResource StaticResource vs DynamicResource are evaluated&lt;/b&gt; only once and only for the purpose. Dynamic resources assessment because each time they are requested by the control, and hence make the request to perform slower. Although this is a deferred execution time search makes sense if the action will not change&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;The use of WPF Performance Suite to the profile of WPF applications&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;WPF Performance Suite is available in the Windows SDK and is composed of a few important profiling tools that allow you to analyze the requests and provide information on the optimizations that can be applied. You can download from the Microsoft website.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The driller and tools of Visual Profiler profiles give much information and also indicate potential bottlenecks in implementation. This suite is part of the Microsoft Windows SDK for Windows 7 and Vista. NET Framework 3. 5 SP1.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Avoid design errors with the help of DesignerProperties. Method GetIsInDesignMode&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Most designers often break the "Could not create an instance" error. Although this is due to some unhandled exception occurs in the constructor's control, may not require the code execution at design time.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="alert"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;public SampleControlConstructor()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; InitializeComponent();&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //place your code here.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Use IsMouseDirectlyOver event to determine the exact mouse movement.&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The event IsMouseOver respond to mouse movement within a control or their children.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;IsMouseDirectlyOver use the event to determine if the mouse movement on the control and not their containers. This is useful for building the triggers specific change in mouse movement.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-3938969734380072409?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/3938969734380072409/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=3938969734380072409' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/3938969734380072409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/3938969734380072409'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/seven-tips-and-tricks-programming-wpf.html' title='Seven Tips and Tricks Programming WPF'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-5819813730722505137</id><published>2011-05-24T22:13:00.001-07:00</published><updated>2011-05-24T22:13:43.283-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>Bind jQuery event handlers for this object CoffeeScript</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;&lt;b&gt;Bind jQuery event handlers for this object CoffeeScript&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Friends have told me that the rich domain objects rarely does so using jQuery to improve performance in web pages. I myself have always loved dynamic JavaScript as a language rich first and something for the second DOM. So most of my client-side JavaScript is an object-oriented robust approach similar to Ruby. This is the main reason they have used Prototype.js for so long.&lt;br /&gt;&lt;br /&gt;Since both jQuery and Rails CoffeeScript announced as the default in version 3.1, I decided it was time to start learning them. I had always known that jQuery linked keyword is in the event handlers to the DOM object. Something you are totally confused and unacceptable for someone working on their own objects to encapsulate behavior. Today I found two ways to deal with my problem, one way and one way CoffeeScript jQuery. First a code example.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;class MyObject&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;constructor: -&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@myDomElement = $('#myDomElement')&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@._initBehavior&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;handler: (event) -&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;console.log(this)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;false&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;_initBehavior: -&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$(window).resize @handler&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;jQuery -&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;window.myObject = new MyObject();&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is a simple class using methods CoffeeScript. Is initialized with a static property this.myDomElement a DOM element on the page with the id "myDomElement." Then, you assign an event handler to the event of resizing the window and records this on the road. Simple things, the only problem is that the registered object will not be an instance of MyObject, but the raw DOM element, in this case the window object. One way to fix this is to use jQuery function as a proxy for&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;_initBehavior: -&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;$(window).resize jQuery.proxy(@handler,this)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This works but seems a little tedious for me and can clog up your initialization code of the event. The other way is to use the arrow operator CoffeeScript fat. An extract from the project page explains it well.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;The fat arrow =&amp;gt; can be used both to define a function, and linked to the current value of this, on the spot. This is useful when using callback libraries based on how Prototype or jQuery, to create a repeater function to pass each, or the event handler functions for use with link. Created with the arrow functions of fat are able to access the properties where they are defined.&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;So all we have to do is change - of&amp;gt; = for any of our callbacks or event handlers, and now this is our own object and not the DOM element. Hot Damn!&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;class MyObject&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;constructor: -&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@myDomElement = $('#myDomElement')&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@._initBehavior&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;handler: (event) =&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;console.log(this)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;false&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;_initBehavior: -&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$(window).resize @handler&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;jQuery -&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;window.myObject = new MyObject();&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-5819813730722505137?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/5819813730722505137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=5819813730722505137' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/5819813730722505137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/5819813730722505137'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/bind-jquery-event-handlers-for-this.html' title='Bind jQuery event handlers for this object CoffeeScript'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-8074799034260578</id><published>2011-05-23T04:42:00.000-07:00</published><updated>2011-05-23T04:42:03.611-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC (Model View Controller)'/><title type='text'>Adding a Controller</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;&lt;h3 style="font-family: Arial, Helvetica, sans-serif; font-size: 0.95em; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;Adding a Controller&lt;/h3&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;MVC stands for&amp;nbsp;&lt;em&gt;model-view-controller&lt;/em&gt;. MVC is a pattern for developing applications that are well architected and easy to maintain. MVC-based applications contain:&lt;/div&gt;&lt;ul style="font-family: Verdana, Helvetica, sans-serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 30px; padding-right: 0px; padding-top: 5px;"&gt;&lt;li style="font-size: 0.7em; padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;Controllers: Classes that handle incoming requests to the application, retrieve model data, and then specify view templates that return a response to the client.&lt;/li&gt;&lt;li style="font-size: 0.7em; padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;Models: Classes that represent the data of the application and that use validation logic to enforce business rules for that data.&lt;/li&gt;&lt;li style="font-size: 0.7em; padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;Views: Template files that your application uses to dynamically generate HTML responses.&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;We'll be covering all these concepts in this tutorial series and show you how to use them to build an application.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;Let's begin by creating a controller class. In&amp;nbsp;&lt;strong&gt;Solution Explorer&lt;/strong&gt;, right-click the&amp;nbsp;&lt;em&gt;Controllers&lt;/em&gt;&amp;nbsp;folder and then select&amp;nbsp;&lt;strong&gt;Add Controller&lt;/strong&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;a href="http://i3.asp.net/common/www-css/i//MVC3/MVC3_gettingStarted_CS/img/AddController.png" style="color: #034efa;"&gt;&lt;img src="http://www.asp.net/media/867173/WindowsLiveWriter_AddingaController_F08A_AddController_sm_thumb.png" style="border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;Name your new controller "HelloWorldController". Leave the default template as&amp;nbsp;&lt;strong&gt;Empty controller&lt;/strong&gt;&amp;nbsp;and click&lt;strong&gt;Add&lt;/strong&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;a href="http://aspnet13.orcsweb.com/media/901289/WindowsLiveWriter_AddingaController_F08A_AddHelloWorldController_6.png" style="color: #034efa;"&gt;&lt;img alt="AddHelloWorldController" border="0" height="389" src="http://www.asp.net/media/901294/WindowsLiveWriter_AddingaController_F08A_AddHelloWorldController_thumb_2.png" style="border-bottom-style: none; border-bottom-width: 0px; border-color: initial; border-color: initial; border-left-style: none; border-left-width: 0px; border-right-style: none; border-right-width: 0px; border-style: initial; border-top-style: none; border-top-width: 0px; border-width: initial; display: inline;" width="556" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;Notice in&amp;nbsp;&lt;strong&gt;Solution Explorer&lt;/strong&gt;&amp;nbsp;that a new file has been created named&amp;nbsp;&lt;em&gt;HelloWorldController.cs&lt;/em&gt;. The file is open in the IDE.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;img src="http://www.asp.net/media/867259/WindowsLiveWriter_AddingaController_F08A_HelloWrldCtrl_thumb_1.png" /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;Inside the&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;public class HelloWorldController&lt;/code&gt;&amp;nbsp;block, create two methods that look like the following code. The controller will return a string of HTML as an example.&lt;/div&gt;&lt;pre class="prettyprint" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-color: rgb(136, 136, 136); border-bottom-style: solid; border-bottom-width: 1px; border-color: initial; border-left-color: rgb(136, 136, 136); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(136, 136, 136); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(136, 136, 136); border-top-style: solid; border-top-width: 1px; border-width: initial; color: #800039; font-family: 'Courier New', Courier, monospace; font-size: 0.7em; overflow-x: scroll; padding-bottom: 2px; padding-left: 2px; padding-right: 2px; padding-top: 2px;"&gt;&lt;span class="kwd" style="color: #000088;"&gt;using&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;System&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;.&lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Web&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;;&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;using&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;System&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;.&lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Web&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;.&lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Mvc&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;;&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;namespace&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;MvcMovie&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;.&lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Controllers&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;{&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;public&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;class&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;HelloWorldController&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;:&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Controller&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;{&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="com" style="color: #880000;"&gt;// &lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="com" style="color: #880000;"&gt;// GET: /HelloWorld/ &lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;public&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;string&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Index&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;()&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;{&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;return&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="str" style="color: #008800;"&gt;"This is my &lt;b&gt;default&lt;/b&gt; action..."&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;;&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;}&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="com" style="color: #880000;"&gt;// &lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="com" style="color: #880000;"&gt;// GET: /HelloWorld/Welcome/ &lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;public&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;string&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Welcome&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;()&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;{&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;return&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="str" style="color: #008800;"&gt;"This is the Welcome action method..."&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;;&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;}&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;}&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;Your controller is named&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;HelloWorldController&lt;/code&gt;&amp;nbsp;and the first method above is named&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;Index&lt;/code&gt;. Let’s invoke it from a browser. Run the application (press F5 or Ctrl+F5). In the browser, append "HelloWorld" to the path in the address bar. (For example, in the illustration below, it's&amp;nbsp;&lt;em&gt;http://localhost:43246/HelloWorld.&lt;/em&gt;) The page in the browser will look like the following screenshot. In the method above, the code returned a string directly. You told the system to just return some HTML, and it did!&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;img src="http://i3.asp.net/common/www-css/i//MVC3/MVC3_gettingStarted_CS/img/IE_helloWorld.PNG" /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;ASP.NET MVC invokes different controller classes (and different action methods within them) depending on the incoming URL. The default mapping logic used by ASP.NET MVC uses a format like this to determine what code to invoke:&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;code style="color: #800039; font-size: 1.2em;"&gt;/[Controller]/[ActionName]/[Parameters]&lt;/code&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;The first part of the URL determines the controller class to execute. So&amp;nbsp;&lt;em&gt;/HelloWorld&lt;/em&gt;&amp;nbsp;maps to the&lt;code style="color: #800039; font-size: 1.2em;"&gt;HelloWorldController&lt;/code&gt;&amp;nbsp;class. The second part of the URL determines the action method on the class to execute. So&amp;nbsp;&lt;em&gt;/HelloWorld/Index&lt;/em&gt;&amp;nbsp;would cause the&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;Index&lt;/code&gt;&amp;nbsp;method of the&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;HelloWorldController&lt;/code&gt;&amp;nbsp;class to execute. Notice that we only had to browse to&amp;nbsp;&lt;em&gt;/HelloWorld&lt;/em&gt;&amp;nbsp;and the&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;Index&lt;/code&gt;&amp;nbsp;method was used by default. This is because a method named&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;Index&lt;/code&gt;&amp;nbsp;is the default method that will be called on a controller if one is not explicitly specified.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;Browse to&amp;nbsp;&lt;em&gt;http://localhost:xxxx/HelloWorld/Welcome&lt;/em&gt;. The&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;Welcome&lt;/code&gt;&amp;nbsp;method runs and returns the string "This is the Welcome action method...". The default MVC mapping is&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;/[Controller]/[ActionName]/[Parameters]&lt;/code&gt;. For this URL, the controller is&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;HelloWorld&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;Welcome&lt;/code&gt;&amp;nbsp;is the action method. You haven't used the&lt;code style="color: #800039; font-size: 1.2em;"&gt;[Parameters]&lt;/code&gt;&amp;nbsp;part of the URL yet.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;img src="http://i3.asp.net/common/www-css/i//MVC3/MVC3_gettingStarted_CS/img/WelcomeAction.PNG" /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;Let's modify the example slightly so that you can pass some parameter information from the URL to the controller (for example,&amp;nbsp;&lt;em&gt;/HelloWorld/Welcome?name=Scott&amp;amp;numtimes=4&lt;/em&gt;). Change your&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;Welcome&lt;/code&gt;&amp;nbsp;method to include two parameters as shown below. Note that the code uses the C# optional-parameter feature to indicate that the&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;numTimes&lt;/code&gt;&amp;nbsp;parameter should default to 1 if no value is passed for that parameter.&lt;/div&gt;&lt;pre class="prettyprint" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-color: rgb(136, 136, 136); border-bottom-style: solid; border-bottom-width: 1px; border-color: initial; border-left-color: rgb(136, 136, 136); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(136, 136, 136); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(136, 136, 136); border-top-style: solid; border-top-width: 1px; border-width: initial; color: #800039; font-family: 'Courier New', Courier, monospace; font-size: 0.7em; overflow-x: scroll; padding-bottom: 2px; padding-left: 2px; padding-right: 2px; padding-top: 2px;"&gt;&lt;span class="kwd" style="color: #000088;"&gt;public&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;string&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Welcome&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;(&lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;string&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; name&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;,&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;int&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; numTimes &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;=&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="lit" style="color: #006666;"&gt;1&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;)&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;{&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;return&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;HttpUtility&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;.&lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;HtmlEncode&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;(&lt;/span&gt;&lt;span class="str" style="color: #008800;"&gt;"Hello "&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;+&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; name &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;+&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="str" style="color: #008800;"&gt;", NumTimes is: "&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;+&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; numTimes&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;);&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;Run your application and browse to the example URL (&lt;em&gt;http://localhost:xxxx/HelloWorld/Welcome?name=Scott&amp;amp;numtimes=4)&lt;/em&gt;. You can try different values for&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;name&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code style="color: #800039; font-size: 1.2em;"&gt;numtimes&lt;/code&gt;&amp;nbsp;in the URL. The system automatically maps the named parameters from the query string in the address bar to parameters in your method.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;img src="http://i3.asp.net/common/www-css/i//MVC3/MVC3_gettingStarted_CS/img/numTimesParam.PNG" /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;In both these examples the controller has been doing the "VC" portion of MVC — that is, the view and controller work. The controller is returning HTML directly. Ordinarily you don't want controllers returning HTML directly, since that becomes very cumbersome to code. Instead we'll typically use a separate view template file to help generate the HTML response. Let's look next at how we can do this.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;b&gt;Related link&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="line-height: 1.4; margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 2.5em; padding-right: 2.5em; padding-top: 0px; text-align: left;"&gt;&lt;b&gt;&lt;li style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; margin-bottom: 0.25em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px;"&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/passing-data-in-aspnet-mvc-application.html" style="color: #990000; text-decoration: underline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: xx-small;"&gt;Passing Data in an ASP.NET MVC Application&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; margin-bottom: 0.25em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px;"&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/aspnet-mvc-overview.html" style="color: #cc0000; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: xx-small;"&gt;ASP.NET MVC Overview&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; margin-bottom: 0.25em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px;"&gt;&lt;span style="color: #cc0000; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: xx-small;"&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/basic-concept-and-fundamentals-of.html" style="color: #cc0000; text-decoration: none;"&gt;Basic concept and fundamentals of ASP.NET MVC (Model View Controller) Architecture&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; margin-bottom: 0.25em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px;"&gt;&lt;i&gt;&lt;span style="color: #cc0000; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: xx-small;"&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/basic-concept-and-fundamentals-of.html" style="color: #cc0000; text-decoration: none;"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small; line-height: 22px;"&gt;&lt;span style="color: #cc0000; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="color: black; line-height: 16px;"&gt;&lt;h3 class="post-title entry-title" style="display: inline !important; font: normal normal normal 22px/normal Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0.75em; position: relative;"&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/aspnet-mvc-3-introduction.html" style="color: #990000; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;ASP.NET MVC 3 Introduction&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;&lt;/b&gt;&lt;/ul&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-8074799034260578?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/8074799034260578/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=8074799034260578' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/8074799034260578'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/8074799034260578'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/adding-controller.html' title='Adding a Controller'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-1118433937459381888</id><published>2011-05-17T13:58:00.000-07:00</published><updated>2011-05-23T04:46:25.027-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC (Model View Controller)'/><title type='text'>ASP.NET MVC 3 Introduction</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 0px; padding-top: 2px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;This article will explain you the basics of ASP.NET MVC 3 Web application by using Microsoft Visual Web Developer 2010 Express Service Pack 1, which is a free version of Microsoft Visual Studio 2010. &amp;nbsp;Make sure you've installed the prerequisites listed below&amp;nbsp;before you start.&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 0px; padding-top: 2px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 0px; padding-top: 2px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;You can install all prerequisites by clicking this link:&amp;nbsp;&lt;a href="http://www.microsoft.com/web/gallery/install.aspx?appid=VWD2010SP1Pack" style="color: #034efa;"&gt;Web Platform Installer&lt;/a&gt;. OR, you can individually install the prerequisites by the following links:&lt;/span&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 30px; padding-right: 0px; padding-top: 5px;"&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;a href="http://www.microsoft.com/web/gallery/install.aspx?appid=VWD2010SP1Pack" style="color: #034efa;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Visual Studio Web Developer Express SP1 prerequisites&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;a href="http://www.microsoft.com/web/gallery/install.aspx?appsxml=&amp;amp;appid=MVC3" style="color: #034efa;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;ASP.NET MVC 3 Tools Update&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;a href="http://www.microsoft.com/web/gallery/install.aspx?appid=SQLCE;SQLCEVSTools_4_0" style="color: #034efa;"&gt;SQL Server Compact 4.0&amp;nbsp;&lt;/a&gt;(runtime + tools support)&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 0px; padding-top: 2px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 0px; padding-top: 2px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;If you're using Visual Studio 2010 instead of Visual Web Developer 2010, install the prerequisites by clicking the following link:&amp;nbsp;&lt;a href="http://www.microsoft.com/web/gallery/install.aspx?appsxml=&amp;amp;appid=VS2010SP1Pack" style="color: #034efa;"&gt;Visual Studio 2010 prerequisites&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 0px; padding-top: 2px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;A Visual Web Developer project with C# source code is available to accompany this topic.&amp;nbsp;&lt;a href="http://code.msdn.microsoft.com/Introduction-to-MVC-3-10d1b098" style="color: #034efa;"&gt;Download the C# version&lt;/a&gt;. If you prefer Visual Basic, switch to the&amp;nbsp;&lt;a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-vb" style="color: #034efa;" target="_blank"&gt;Visual Basic version&lt;/a&gt;&amp;nbsp;of this tutorial.&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 0px; padding-top: 2px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 0px; padding-top: 2px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style="margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;What You'll Build&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;You'll implement a simple movie-listing application that supports creating, editing, and listing movies from a database. Below are two screenshots of the application you’ll build. It includes a page that displays a list of movies from a database:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;span class="Apple-style-span" style="clear: left; float: left; font-family: Verdana, sans-serif; font-size: x-small; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="405" src="http://3.bp.blogspot.com/-f321JwL83Oc/TdLgLBGuMxI/AAAAAAAAANE/mcRrdFYo99Q/s640/MVC+1.png" width="640" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;The application also lets you add, edit, and delete movies, as well as see details about individual ones. All data-entry scenarios include validation to ensure that the data stored in the database is correct.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small; margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-SOeQBSaA-Uw/TdLgLyDxAtI/AAAAAAAAANI/VH_CBrygllE/s640/MVC+2.png" width="556" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style="margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Skills You'll Learn&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Here's what you'll learn:&lt;/span&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 30px; padding-right: 0px; padding-top: 5px;"&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;How to create a new ASP.NET MVC project.&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;How to create ASP.NET MVC controllers and views.&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;How to create a new database using the Entity Framework Code First paradigm.&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;How to retrieve and display data.&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;How to edit data and enable data validation.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 style="margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Getting Started&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Start by running Visual Web Developer 2010 Express ("Visual Web Developer" for short) and select&amp;nbsp;&lt;strong&gt;New Project&lt;/strong&gt;&amp;nbsp;from the&amp;nbsp;&lt;strong&gt;Start&lt;/strong&gt;&amp;nbsp;page.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Visual Web Developer is an IDE, or integrated development environment. Just like you use Microsoft Word to write documents, you'll use an IDE to create applications. In Visual Web Developer there's a toolbar along the top showing various options available to you. There's also a menu that provides another way to perform tasks in the IDE. (For example, instead of selecting&amp;nbsp;&lt;strong&gt;New Project&lt;/strong&gt;&amp;nbsp;from the&amp;nbsp;&lt;strong&gt;Start&lt;/strong&gt;&amp;nbsp;page, you can use the menu and select&lt;strong&gt;File&lt;/strong&gt;&amp;nbsp;&amp;gt;&amp;nbsp;&lt;strong&gt;New Project&lt;/strong&gt;.)&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;span class="Apple-style-span" style="clear: left; float: left; font-family: Verdana, sans-serif; font-size: x-small; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="510" src="http://3.bp.blogspot.com/-_Jmha0PKr7Q/TdLgM5fChgI/AAAAAAAAANM/BALfwxaBwds/s640/MVC+3.PNG" width="640" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style="margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Creating Your First Application&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;You can create applications using either Visual Basic or Visual C# as the programming language. Select Visual C# on the left and then select&amp;nbsp;&lt;strong&gt;ASP.NET MVC 3 Web Application&lt;/strong&gt;. Name your project "MvcMovie" and then click&amp;nbsp;&lt;strong&gt;OK&lt;/strong&gt;. (If you prefer Visual Basic, switch to the&amp;nbsp;&lt;a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-vb" style="color: #034efa;" target="_blank"&gt;Visual Basic version&lt;/a&gt;&amp;nbsp;of this tutorial.)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-poeCRbifgX8/TdLgNgqoLHI/AAAAAAAAANQ/HCHmlIzHkHA/s1600/MVC+4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;img border="0" height="273" src="http://3.bp.blogspot.com/-poeCRbifgX8/TdLgNgqoLHI/AAAAAAAAANQ/HCHmlIzHkHA/s400/MVC+4.PNG" width="400" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;In the&amp;nbsp;&lt;strong&gt;New ASP.NET MVC 3 Project&lt;/strong&gt;&amp;nbsp;dialog box, select&amp;nbsp;&lt;strong&gt;Internet Application&lt;/strong&gt;. Check&amp;nbsp;&lt;strong&gt;Use HTML5 markup&lt;/strong&gt;and leave&amp;nbsp;&lt;strong&gt;Razor&lt;/strong&gt;&amp;nbsp;as the default view engine.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-536NLvaqmCk/TdLgOCJ1PmI/AAAAAAAAANU/t8J2xXjTxYY/s1600/MVC+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-536NLvaqmCk/TdLgOCJ1PmI/AAAAAAAAANU/t8J2xXjTxYY/s1600/MVC+5.png" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Click&amp;nbsp;&lt;strong&gt;OK&lt;/strong&gt;. Visual Web Developer used a default template for the ASP.NET MVC project you just created, so you have a working application right now without doing anything! This is a simple "Hello World!" project, and it's a good place to start your application.&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;span class="Apple-style-span" style="clear: left; float: left; font-family: Verdana, sans-serif; font-size: x-small; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="510" src="http://1.bp.blogspot.com/-W8wvxg1zcT4/TdLgPEPe9GI/AAAAAAAAANY/VXuq-FUBHAA/s640/MVC+6.PNG" width="640" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;From the&amp;nbsp;&lt;strong&gt;Debug&lt;/strong&gt;&amp;nbsp;menu, select&amp;nbsp;&lt;strong&gt;Start Debugging&lt;/strong&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-EOR151whAcg/TdLgPjVl9FI/AAAAAAAAANc/wI7GK1PFiMo/s1600/MVC+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-EOR151whAcg/TdLgPjVl9FI/AAAAAAAAANc/wI7GK1PFiMo/s1600/MVC+7.png" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Notice that the keyboard shortcut to start debugging is F5.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;F5 causes Visual Web Developer to start a development web server and run your web application. Visual Web Developer then launches a browser and opens the application's home page. Notice that the address bar of the browser says&amp;nbsp;&lt;code style="color: #800039;"&gt;localhost&lt;/code&gt;&amp;nbsp;and not something like&amp;nbsp;&lt;code style="color: #800039;"&gt;example.com&lt;/code&gt;. That's because&amp;nbsp;&lt;code style="color: #800039;"&gt;localhost&lt;/code&gt;&amp;nbsp;always points to your own local computer, which in this case is running the application you just built. When Visual Web Developer runs a web project, a random port is used for the web server. In the image below, the random port number is 43246. When you run the application, you'll probably see a different port number.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;span class="Apple-style-span" style="clear: left; float: left; font-family: Verdana, sans-serif; font-size: x-small; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="423" src="http://2.bp.blogspot.com/-ibafzNl_E28/TdLgQcCxpkI/AAAAAAAAANg/YYnivpOdLSU/s640/MVC+8.PNG" width="640" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Right out of the box this default template gives you two pages to visit and a basic login page. The next step is to change how this application works and learn a little bit about ASP.NET MVC in the process. Close your browser and let's change some code.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;b&gt;Related links:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="line-height: 1.4; margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 2.5em; padding-right: 2.5em; padding-top: 0px; text-align: left;"&gt;&lt;li style="margin-bottom: 0.25em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;b&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/passing-data-in-aspnet-mvc-application.html" style="color: #990000; text-decoration: underline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: xx-small;"&gt;Passing Data in an ASP.NET MVC Application&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="margin-bottom: 0.25em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;b&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/aspnet-mvc-overview.html" style="color: #cc0000; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: xx-small;"&gt;ASP.NET MVC Overview&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="margin-bottom: 0.25em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;b style="color: #cc0000; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: xx-small;"&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/basic-concept-and-fundamentals-of.html" style="color: #cc0000; text-decoration: none;"&gt;Basic concept and fundamentals of ASP.NET MVC (Model View Controller) Architecture&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="margin-bottom: 0.25em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b style="color: #cc0000; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/basic-concept-and-fundamentals-of.html" style="color: #cc0000; text-decoration: none;"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; line-height: 18px;"&gt;&lt;b style="color: #cc0000; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="color: black; font-weight: normal; line-height: 16px;"&gt;&lt;h3 class="post-title entry-title" style="display: inline !important; font: normal normal normal 22px/normal Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0.75em; position: relative;"&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/adding-controller.html" style="color: #990000; text-decoration: none;"&gt;Adding a Controller&lt;/a&gt;&lt;/h3&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 2.5em; padding-right: 2.5em; padding-top: 0px; text-align: left;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;li style="display: inline !important; font-weight: bold; line-height: 1.4; margin-bottom: 0.25em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal; line-height: 16px;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;&lt;div style="font-size: small;"&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-1118433937459381888?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/1118433937459381888/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=1118433937459381888' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/1118433937459381888'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/1118433937459381888'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/aspnet-mvc-3-introduction.html' title='ASP.NET MVC 3 Introduction'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-f321JwL83Oc/TdLgLBGuMxI/AAAAAAAAANE/mcRrdFYo99Q/s72-c/MVC+1.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-3424463942139818767</id><published>2011-05-16T00:25:00.000-07:00</published><updated>2011-05-17T13:22:24.635-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC (Model View Controller)'/><title type='text'>Introducing MVC Development w/the Razor View Engine for Visual Studio Developers</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 13px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The Razor View Engine is a precise, useful, light language that enables you to create views for MVC projects in ASP.NET still while keeping a separation of concerns, ability to test, and pattern based development.&amp;nbsp; ASP.NET MVC developers looking for a more concise syntax now have another option that's built-in (of course, there are many 3rd party view engines out there) with the language being a familiar light version of C#.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The Razor View engine is used to create WebMatrix sites or Visual Studio MVC applications.&amp;nbsp; When using ASP.NET MVC with either engine, you'll stick to a style of development called "convention over configuration", meaning that you'll use certain naming conventions to name files, models, views, controllers, and other key application elements rather than storing lots of metadata about these same elements in a configuration file.&amp;nbsp; When using MVC in Visual Studio 2010, it's is setup so that you'll be guided to use convention over configuration, which becomes evident when exploring an ASP.NET MVC project.&lt;/span&gt;&lt;/div&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 1.231em; font-style: inherit; font-weight: normal; margin-bottom: 0.6em; margin-left: 0px; margin-right: 0px; margin-top: 0.6em; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 16px; font-style: inherit; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Getting Started&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Before you start, go and download these two things (as of this post; things are subject to change - these could end up in VS at some point):&lt;/span&gt;&lt;/div&gt;&lt;ul style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; list-style-image: initial; list-style-position: initial; list-style-type: disc; margin-bottom: 1.5em; margin-left: 1.5em; margin-right: 1.5em; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;li style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;ASP.NET&amp;nbsp;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=cb42f741-8fb1-4f43-a5fa-812096f8d1e8&amp;amp;displaylang=en" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #666666; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;MVC 3&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/en-us/8dc77b9c-7c83-4392-9c46-fd15f3927a2e" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #666666; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;Razor Syntax Highlighter Extension&lt;/a&gt;&amp;nbsp;(not mandatory, but a huge help)&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;You can also find the Razor Syntax Highlighter by choosing&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Extensions Manager&lt;/em&gt;&amp;nbsp;from the Visual Studio&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Tools&lt;/em&gt;&amp;nbsp;menu.&amp;nbsp; Once installed, MVC 3 project templates are available from Visual Studio.&amp;nbsp; The MVC 3 Web Application template allows you to use either the Web Forms View Engine or the Razor View Engine, while MVC 2 Applications contain only the WF View Engine.&lt;/span&gt;&lt;/div&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://rachelappel.com/Media/Default/Windows-Live-Writer/TheRazorViewEngineinMVCProjects_9224/image_2.png" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #666666; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;"&gt;&lt;img alt="image" border="0" height="308" src="http://rachelappel.com/Media/Default/Windows-Live-Writer/TheRazorViewEngineinMVCProjects_9224/image_thumb.png" style="background-image: none; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; display: inline; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;" title="image" width="444" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;When creating a new MVC 3 project a new dialog box appears asking which application type, view engine, and testing framework you'd like to use.&amp;nbsp; You can and&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;should&lt;/em&gt;&amp;nbsp;add a test project so you can test your code, then actually write some tests in it.&amp;nbsp;&amp;nbsp; The image below demonstrates selecting the internet application project template using Razor as the view engine, as well as the test framework.&amp;nbsp; The internet application MVC template adds in ASP.NET membership &amp;amp; security features to the project by creating the necessary model, view and controller for logging on and registering as a site user.&lt;/span&gt;&lt;/div&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://rachelappel.com/Media/Default/Windows-Live-Writer/TheRazorViewEngineinMVCProjects_9224/image_6.png" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #666666; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;"&gt;&lt;img alt="image" border="0" height="400" src="http://rachelappel.com/Media/Default/Windows-Live-Writer/TheRazorViewEngineinMVCProjects_9224/image_thumb_2.png" style="background-image: none; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; display: inline; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;" title="image" width="444" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Verify that the project is created with three folders, one each for Models, Views, and Controllers which is the same folder structure as a MVC 2 site.&amp;nbsp; The project also contains auxiliary folders and files needed for the application such as the Content &amp;amp; App_Data folders.&amp;nbsp;&amp;nbsp; Since this is an MVC application using the Razor View Engine, you will see a different file extension - .&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;cshtml&lt;/em&gt;.&amp;nbsp; The&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;.cshtml&lt;/em&gt;&amp;nbsp;files are Razor View Pages written using the Razor View Engine.&amp;nbsp; If you're not familiar with Razor syntax, I've blogged about it&amp;nbsp;&lt;a href="http://rachelappel.com/webmatrix/getting-familiar-with-razor-language-syntax-features-and-rules/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #666666; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;here&lt;/a&gt;, and the online documentation has&amp;nbsp;&lt;a href="http://www.asp.net/webmatrix/tutorials/2-introduction-to-asp-net-web-programming-using-the-razor-syntax" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #666666; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;more information&lt;/a&gt;&amp;nbsp;as well.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://rachelappel.com/Media/Default/Windows-Live-Writer/TheRazorViewEngineinMVCProjects_9224/image_11.png" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #666666; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;"&gt;&lt;img alt="image" border="0" height="434" src="http://rachelappel.com/Media/Default/Windows-Live-Writer/TheRazorViewEngineinMVCProjects_9224/image_thumb_4.png" style="background-image: none; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; display: inline; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;" title="image" width="244" /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The application template sets up some models, views and controllers to start with, and is now ready for new models, views, and controllers.&amp;nbsp; I've found the easiest way to work with MVC in VS is to start with the model, move to the controller, then create the view, so we'll look at models first.&lt;/span&gt;&lt;/div&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 1.231em; font-style: inherit; font-weight: normal; margin-bottom: 0.6em; margin-left: 0px; margin-right: 0px; margin-top: 0.6em; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 16px; font-style: inherit; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Models&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;A model is a representation of an underlying data store.&amp;nbsp; Models can be almost anything from any data source; EF or Linq2Sql Models, or a simple class.&amp;nbsp; The code the builds the model below consists of two classes, a&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;ProductModel&lt;/em&gt;&amp;nbsp;class and a&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Product&lt;/em&gt;&amp;nbsp;class.&amp;nbsp; The&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;ProductModel&lt;/em&gt;&amp;nbsp;class returns a&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;List&lt;t&gt;&lt;/t&gt;&lt;/em&gt;&amp;nbsp;of&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Product&lt;/em&gt;&amp;nbsp;objects in a property aptly named&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Products&lt;/em&gt;&amp;nbsp;that represents one or more products in the data store .&amp;nbsp;&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Product&lt;/em&gt;&amp;nbsp;objects contain&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;ProductNumber, Name&lt;/em&gt;&amp;nbsp;and&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Price&lt;/em&gt;&amp;nbsp;properties and represent an individual product in the data store.&amp;nbsp; The model code representing these product objects is below:&lt;/span&gt;&lt;/div&gt;&lt;pre style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; font: normal normal normal 1em/normal 'andale mono', 'lucida console', monospace; line-height: 1.462em; margin-bottom: 0.923em; margin-left: 0px; margin-right: 0px; margin-top: 0.923em; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; white-space: pre;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 13px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: xx-small; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: xx-small; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt; System.Collections.Generic;&lt;br /&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;namespace&lt;/span&gt;&lt;/span&gt; AdventureWorks.Models&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;public&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;class&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;ProductModel&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;public&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;List&lt;/span&gt;&lt;/span&gt;&amp;lt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Product&lt;/span&gt;&lt;/span&gt;&amp;gt; Products { &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;get&lt;/span&gt;&lt;/span&gt;; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;set&lt;/span&gt;&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;public&lt;/span&gt;&lt;/span&gt; ProductModel()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Products = &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;new&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;List&lt;/span&gt;&lt;/span&gt;&amp;lt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Product&lt;/span&gt;&lt;/span&gt;&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;this&lt;/span&gt;&lt;/span&gt;.Products.Add(&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;new&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Product&lt;/span&gt;&lt;/span&gt;(&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #a31515; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;"AB-00-J1"&lt;/span&gt;&lt;/span&gt; ,&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #a31515; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;"Super Fast Bike"&lt;/span&gt;&lt;/span&gt; ,1000M));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;this&lt;/span&gt;&lt;/span&gt;.Products.Add(&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;new&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Product&lt;/span&gt;&lt;/span&gt;(&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #a31515; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;"EE-9-OL"&lt;/span&gt;&lt;/span&gt;&amp;nbsp; ,&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #a31515; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;"Durable Helmet"&lt;/span&gt;&lt;/span&gt;&amp;nbsp; ,123.45M));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;this&lt;/span&gt;&lt;/span&gt;.Products.Add(&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;new&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Product&lt;/span&gt;&lt;/span&gt;(&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #a31515; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;"MMM99-54"&lt;/span&gt;&lt;/span&gt; ,&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #a31515; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;"Soft Bike Seat"&lt;/span&gt;&lt;/span&gt;&amp;nbsp; ,34.99M));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;public&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;class&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;Product&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;public&lt;/span&gt;&lt;/span&gt; Product(&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;string&lt;/span&gt;&lt;/span&gt; productNumber, &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;string&lt;/span&gt;&lt;/span&gt; name, &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;decimal&lt;/span&gt;&lt;/span&gt; price)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name = name;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Price = price;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProductNumber=productNumber;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;public&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;string&lt;/span&gt;&lt;/span&gt; ProductNumber { &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;get&lt;/span&gt;&lt;/span&gt;; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;set&lt;/span&gt;&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;public&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;string&lt;/span&gt;&lt;/span&gt; Name { &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;get&lt;/span&gt;&lt;/span&gt;; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;set&lt;/span&gt;&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;public&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;decimal&lt;/span&gt;&lt;/span&gt; Price { &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;get&lt;/span&gt;&lt;/span&gt;; &lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; font-size: 10px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;set&lt;/span&gt;&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: inherit; font-weight: inherit; line-height: 1.538em; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Models are handed over to views by controllers so the views can render the data from the model.&amp;nbsp; The model will extend business logic (of course, this is a simple example, business logic will likely be spread out into other applications &amp;amp; tiers). Models also provide validation information to the view via metadata &amp;amp; code.&amp;nbsp; You can add the model to the&amp;nbsp;&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;\Models&lt;/em&gt;&amp;nbsp;folder or you can reference an external data model library.&amp;nbsp; In this case, the model's been added to the&lt;em style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 13px; font-style: italic; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&amp;nbsp;\Models&lt;/em&gt;&amp;nbsp;folder.&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;See full details:&amp;nbsp;&lt;a href="http://rachelappel.com/razor/introducing-mvc-development-w-the-razor-view-engine-for-visual-studio-developers/" target="_blank"&gt;http://rachelappel.com/razor/introducing-mvc-development-w-the-razor-view-engine-for-visual-studio-developers/&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Related link&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/passing-data-in-aspnet-mvc-application.html"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Passing Data in an ASP.NET MVC Application&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/aspnet-mvc-overview.html"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;ASP.NET MVC Overview&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/basic-concept-and-fundamentals-of.html"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;Basic concept and fundamentals of ASP.NET MVC (Model View Controller) Architecture&lt;/span&gt;&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-3424463942139818767?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/3424463942139818767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=3424463942139818767' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/3424463942139818767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/3424463942139818767'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/introducing-mvc-development-wthe-razor.html' title='Introducing MVC Development w/the Razor View Engine for Visual Studio Developers'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-1095113339587318892</id><published>2011-05-15T10:46:00.000-07:00</published><updated>2011-05-15T10:46:44.266-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>LINQ to SQL</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;LINQ to SQL allows .NET developers to write “queries” in their .NET language of  choice to retrieve and manipulate data from a SQL Server database. In a general  sense, LINQ to SQL allows us to create SQL queries in our preferred .NET  language syntax and work with a strongly types collection of objects as a return  result. We can make changes to these objects then save changes back to the  database. &lt;br /&gt;&lt;br /&gt;To get an idea of the syntax for LINQ to SQL, we will be using  the following SQL database schema. It is a simple software registration and  helpdesk. It is populated with sample data and has foreign-key relationships  defined where appropriate.&lt;br /&gt;&lt;br /&gt;&lt;img alt="SQL Database Schema used for LINQ to SQL examples" src="http://www.hookedonlinq.com/GetFile.aspx?File=Images%2fLINQtoSQL_Database+Schema.png" /&gt;&lt;br /&gt;&lt;b&gt;SQL  Database Schema used for LINQ to SQL examples.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;For the moment I ask  you to ignore the fact that we will be coding against a type HookedOnLINQ, I’ll  get to how that was created in a few pages time, for now just understand it is  an object structure that mimics this database schema.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;HookedOnLINQ db =       &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: green;"&gt;new&lt;/span&gt;&lt;/a&gt; HookedOnLINQ&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: grey;"&gt;"Data Source=(local);Initial Catalog=HookedOnLINQ"&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt;;  &amp;nbsp;    var q = from c &lt;span style="color: #0600ff;"&gt;in&lt;/span&gt; db.&lt;span style="color: blue;"&gt;Contact&lt;/span&gt;            where c.&lt;span style="color: blue;"&gt;DateOfBirth&lt;/span&gt;.&lt;span style="color: blue;"&gt;AddYears&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;35&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt; &amp;gt; DateTime.&lt;span style="color: blue;"&gt;Now&lt;/span&gt;            orderby c.&lt;span style="color: blue;"&gt;DateOfBirth&lt;/span&gt; descending            select c; &amp;nbsp;    &lt;span style="color: #0600ff;"&gt;foreach&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;var c &lt;span style="color: #0600ff;"&gt;in&lt;/span&gt; q&lt;span style="color: black;"&gt;)&lt;/span&gt;        Console.&lt;span style="color: blue;"&gt;WriteLine&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: grey;"&gt;"{0} {1} b.{2}"&lt;/span&gt;,                    c.&lt;span style="color: blue;"&gt;FirstName&lt;/span&gt;.&lt;span style="color: blue;"&gt;Trim&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt;,                    c.&lt;span style="color: blue;"&gt;LastName&lt;/span&gt;.&lt;span style="color: blue;"&gt;Trim&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt;,c.&lt;span style="color: blue;"&gt;DateOfBirth&lt;/span&gt;.&lt;span style="color: blue;"&gt;ToString&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: grey;"&gt;"dd-MMM-yyyy"&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt;; &amp;nbsp; Output: Mack Kamph b&lt;span style="color: red;"&gt;.17&lt;/span&gt;-Sep&lt;span style="color: red;"&gt;-1977&lt;/span&gt; Armando Valdes b&lt;span style="color: red;"&gt;.09&lt;/span&gt;-Dec&lt;span style="color: red;"&gt;-1973&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red; font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;See full details:&amp;nbsp;&lt;a href="http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx" target="_blank"&gt;http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-1095113339587318892?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/1095113339587318892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=1095113339587318892' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/1095113339587318892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/1095113339587318892'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/linq-to-sql.html' title='LINQ to SQL'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-403629598882025256</id><published>2011-05-15T10:31:00.000-07:00</published><updated>2011-05-15T10:31:29.270-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC (Model View Controller)'/><title type='text'>Passing Data in an ASP.NET MVC Application</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The ASP.NET MVC framework provides page-level containers that can pass data between controllers and views. This topic&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;explains how to pass both weakly typed and strongly typed data in an MVC application. It also explains how to pass&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;temporary state data between action methods&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Passing Data Between a Controller and a View&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;To render a view, you call the View method of the controller. To pass data to the view, you use the ViewData property of&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;the ViewPage class. This property returns aViewDataDictionary object that has case-insensitive string keys. To pass data to&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;the view, you can assign values to the dictionary, as shown in the following example:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;List&amp;lt;string&amp;gt; petList = new List&amp;lt;string&amp;gt;();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;petList.Add("Dog");&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;petList.Add("Cat");&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;petList.Add("Hamster");&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;petList.Add("Parrot");&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;petList.Add("Gold fish");&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;petList.Add("Mountain lion");&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;petList.Add("Elephant");&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;ViewData["Pets"] = new SelectList(petList);&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;If you call the View method without parameters (as shown in the previous example), the controller object's ViewData&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;property is passed to the view that has the same name as the action method.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In the view page, you can access the ViewData property to obtain data that was passed to the view. The ViewData property is&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;a dictionary that supports an indexer that accepts dictionary keys.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The following example shows the markup for a view that displays the data in an HTML form and enables the user to modify&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;values and make selections.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;lt;h2&amp;gt;&amp;lt;%= Html.Encode(ViewData["Message"]) %&amp;gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;lt;% using(Html.BeginForm("HandleForm", "Home")) %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;lt;% { %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Enter your name: &amp;lt;%= Html.TextBox("name") %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Select your favorite color:&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;%= Html.RadioButton("favColor", "Blue", true) %&amp;gt; Blue &amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;%= Html.RadioButton("favColor", "Purple", false)%&amp;gt; Purple &amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;%= Html.RadioButton("favColor", "Red", false)%&amp;gt; Red &amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;%= Html.RadioButton("favColor", "Orange", false)%&amp;gt; Orange &amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;%= Html.RadioButton("favColor", "Yellow", false)%&amp;gt; Yellow &amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;%= Html.RadioButton("favColor", "Brown", false)%&amp;gt; Brown &amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;%= Html.RadioButton("favColor", "Green", false)%&amp;gt; Green &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;%= Html.CheckBox("bookType") %&amp;gt; I read more fiction than non-fiction.&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;My favorite pet: &amp;lt;%= Html.DropDownList("pets") %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input type="submit" value="Submit" /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;lt;% } %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Passing Strongly-Typed Data Between a Controller and a View&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;When you pass data between a view and a controller by using the ViewData property of the ViewPage class, the data is not&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;strongly typed. If you want to pass strongly typed data, change the @ Page declaration of the view so that the view&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;inherits from ViewPage&lt;tmodel&gt; instead of from ViewPage, as shown in the following example&lt;/tmodel&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;lt;%@ Page Inherits="ViewPage&amp;lt;Product&amp;gt;" %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;ViewPage&amp;lt;TModel&amp;gt; is the strongly-typed version of ViewPage. The ViewData property of ViewPage&lt;tmodel&gt; returns a&amp;nbsp;&lt;/tmodel&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;ViewDataDictionary&lt;tmodel&gt; object, which contains strongly typed data for the view based on a model. The model is a class&amp;nbsp;&lt;/tmodel&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;that contains properties for each data item that you want to pass. (A simpler approach to creating a strongly typed view&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;page is to use the Add View dialog box.)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The following example shows the definition of a typical data model class named Person.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;using System;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;using System.Collections.Generic;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;using System.Linq;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;using System.Web;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;using System.ComponentModel.DataAnnotations;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;namespace MvcDataViews.Models&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public class Person&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Required(ErrorMessage = "The ID is required.")]&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public int Id { get; set; }&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Required(ErrorMessage = "The name is required.")]&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public string Name { get; set; }&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Range(1, 200, ErrorMessage = "A number between 1 and 200.")]&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public int Age { get; set; }&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[RegularExpression(@"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}", &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ErrorMessage = "Invalid phone number.")]&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public string Phone { get; set; }&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[RegularExpression(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$", &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ErrorMessage = "Invalid email address.")]&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public string Email { get; set; }&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The following example shows a view that enables the user to modify the values of a Person object and to submit the changes&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;for update.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The following example shows the action method that receives a Person object from the Edit view, checks its validity against&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;the model, updates a list of Person objects, and then redirects to the Index action.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Action methods might have to pass data to another action, such as if an error occurs when a form is being posted, or if the&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;method must redirect to additional methods, as might occur when the user is directed to a login view and then back to the&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;original action method.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Passing State Between Action Methods&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;An action method can store data in the controller's TempDataDictionary object before it calls the controller's&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;RedirectToAction method to invoke the next action. The TempData property value is stored in session state. Any action&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;method that is called after the TempDataDictionary value is set can get values from the object and then process or display&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;them. The value of TempData persists until it is read or until the session times out. Persisting TempData in this way&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;enables scenarios such as redirection, because the values in TempData are available beyond a single request.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Note: This behavior is new in ASP.NET MVC 2. In earlier versions of ASP.NET MVC, the values in TempData was available only&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;until the next request.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The following example shows a data class that is used to trap an error and to transfer data between actions.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;public class InsertError&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public string ErrorMessage { get; set; }&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public string OriginalFirstName { get; set; }&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public string OriginalLastName { get; set; }&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;// CustomersController&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;public ActionResult InsertCustomer(string firstName, string lastName)&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Check for input errors.&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (String.IsNullOrEmpty(firstName) ||&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String.IsNullOrEmpty(lastName))&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InsertError error = new InsertError();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;error.ErrorMessage = "Both names are required.";&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;error.OriginalFirstName = firstName;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;error.OriginalLastName = lastName;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TempData["error"] = error;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return RedirectToAction("NewCustomer");&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// No errors&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ...&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return View();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;public ActionResult NewCustomer()&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InsertError err = TempData["error"] as InsertError;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (err != null)&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// If there is error data from the previous action, display it.&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ViewData["FirstName"] = err.OriginalFirstName;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ViewData["LastName"] = err.OriginalLastName;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ViewData["ErrorMessage"] = err.ErrorMessage;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ...&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return View();&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The following example shows the markup for a view that accepts user input and displays an error message if an error occurs.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;lt;form action="/Home/InsertCustomer"&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;% if (ViewData["ErrorMessage"] != null) { %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;The following error occurred while inserting the customer data:&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;%= ViewData["ErrorMessage"] %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;% } %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;First name: &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;input type="text" name="firstName" value="&amp;lt;%= ViewData["FirstName"] %&amp;gt;" /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;Last name: &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;input type="text" name="lastName" value="&amp;lt;%= ViewData["LastName"] %&amp;gt;" /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;br /&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;input type="submit" value="Insert" /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-403629598882025256?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/403629598882025256/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=403629598882025256' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/403629598882025256'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/403629598882025256'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/passing-data-in-aspnet-mvc-application.html' title='Passing Data in an ASP.NET MVC Application'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-6674278913092623389</id><published>2011-05-10T06:09:00.000-07:00</published><updated>2011-05-10T06:09:53.301-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC (Model View Controller)'/><title type='text'>ASP.NET MVC Overview</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, sans-serif; font-size: 13px; line-height: 16px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;h2 style="font-family: Verdana, Arial, sans-serif; font-size: 13pt; font-weight: bold; line-height: 1.2em;"&gt;Introduction&lt;/h2&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;ASP.NET MVC is one of the methods of developing ASP.NET applications. In this article, we will go through the overview of ASP.NET MVC by creating a simple application.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;ASP.NET MVC Framework is Microsoft’s Web Application development framework, the other one being traditional webforms framework.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;MVC or Model View Controller is a design pattern that addresses the separation of concerns(Soc) which is the process of identifying and separating the application into distinct parts like UI, Logic and Data Access.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;Soc has proven to be useful in the design of web applications. Keeping the view separate from the other parts of the application means that we can easily change the view without affecting the rest of the application.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;Similarly, if we want to change the main application logic, we just need to change the controller.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;ASP.NET MVC is an implementation of the MVC design pattern. The framework helps Test Driven Development which is a method of development in which Unit Test Cases are written before the rest of the application.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;img border="0" complete="true" height="202" hspace="0" src="http://www.codeproject.com/KB/aspnet/ASPNETMVCOverview/image001.gif" style="height: 202px; overflow-x: auto; overflow-y: auto; width: 408px;" width="408" /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, sans-serif; font-size: 13px; line-height: 16px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;The above diagram shows the relationship between the MVC Framework and the .NET Framework. Observe that the Web Forms and MVC are both built on top of ASP.NET Framework.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;While building web applications, developers can either choose the web forms model or the MVC model depending on the requirements of the application.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;An MVC application consists of Model, View and Controller at its core:&lt;/div&gt;&lt;ol&gt;&lt;li style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;strong&gt;Model&lt;/strong&gt;: Consists of the data access logic and the classes that represent the objects in the application domain (Business Objects)&lt;/li&gt;&lt;li style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;strong&gt;View&lt;/strong&gt;: A view contains HTML markup&lt;/li&gt;&lt;li style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;strong&gt;Controller&lt;/strong&gt;: Consists of the main application flow logic&lt;/li&gt;&lt;/ol&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;Let’s start with creating simple MVC application to understand the basics of the MVC application. We will start by creating a blank ASP.NET MVC application.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;Once the web application is created, we will add the functionality to make it work.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;img border="0" complete="true" height="360" hspace="0" src="http://www.codeproject.com/KB/aspnet/ASPNETMVCOverview/image004_small.png" style="height: 360px; overflow-x: auto; overflow-y: auto; width: 640px;" width="640" /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;img border="0" complete="true" height="321" hspace="0" src="http://www.codeproject.com/KB/aspnet/ASPNETMVCOverview/image007.png" style="height: 321px; overflow-x: auto; overflow-y: auto; width: 252px;" width="252" /&gt;&lt;/div&gt;&lt;h4 style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; font-weight: bold; line-height: 1.2em;"&gt;Adding the Controller&lt;/h4&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;For adding the controller, we will right click the&amp;nbsp;&lt;em&gt;controllers&lt;/em&gt;&amp;nbsp;folder and select Add -&amp;gt; Controller. We will type the name&amp;nbsp;&lt;code style="color: #990000; font: normal normal normal 11pt/normal 'Courier New', Courier, mono;"&gt;NamesController&amp;nbsp;&lt;/code&gt;in controller name dialog.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;Note that the Controller name must end with Suffix Controller. Doing so creates a controller with the default code. We have renamed the action as in the following code.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;img border="0" complete="true" height="340" hspace="0" src="http://www.codeproject.com/KB/aspnet/ASPNETMVCOverview/image010.jpg" style="height: 340px; overflow-x: auto; overflow-y: auto; width: 624px;" width="624" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;See full details:&amp;nbsp;&lt;a href="http://www.codeproject.com/KB/aspnet/ASPNETMVCOverview.aspx" target="_blank"&gt;http://www.codeproject.com/KB/aspnet/ASPNETMVCOverview.aspx&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-6674278913092623389?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/6674278913092623389/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=6674278913092623389' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/6674278913092623389'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/6674278913092623389'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/aspnet-mvc-overview.html' title='ASP.NET MVC Overview'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-806313348695701690</id><published>2011-05-10T06:03:00.000-07:00</published><updated>2011-05-17T13:15:26.695-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Implement a Cancel button while using Bindings, and send only an object's changes to a WCF service</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, sans-serif; font-size: 13px; line-height: 16px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;h2 style="color: #ff9900; font-family: Verdana, Arial, sans-serif; font-size: 13pt; font-weight: bold; line-height: 1.2em;"&gt;&lt;span class="Apple-style-span" style="color: black; font-size: 13px; font-weight: normal; line-height: 16px;"&gt;Take the following scenario: A user of your application opens a customer for editing. They put in a new address. Now they realize they're in the wrong customer entirely and want to cancel their changes.&lt;/span&gt;&lt;/h2&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;What does your application do? If you're like me, then you are on a mission to keep code behind to an absolute minimum. You have two way bindings setup for everything. You're proud of all the C#/VB code that you&amp;nbsp;&lt;em&gt;haven't&lt;/em&gt;&amp;nbsp;written in your application. So, your model is already updated. Do you not have a cancel button? Blame the user for the bad experience and tell them not to do that? Or did you add a reload method to your cancel button instead, forcing the application to grab data from a web service or a database?&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;Another possible option might have been to follow MVVM completely and to separate the Model from the ViewModel even on the most basic classes. The ViewModel could then store copies of this data and include methods to move back to the object and to reload data from the object. The downside here is that you need to add properties twice, and always remember to include them in your methods. This is a lot of code duplication.&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;Here's another predicament: You use a web service for your data source. You'd like to keep the data sent across the Internet to a minimum. But your class has 100+ properties. Sure, only one might have changed, but how do you know which ones have changed? Do you serialize the entire class to send it? Do you create 100 variables called OrgAddress, OrgName, etc?&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;I'd like to share a solution to both of these that has worked for me: A special base class. &amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;/div&gt;&lt;h2 style="font-family: Verdana, Arial, sans-serif; font-size: 13pt; font-weight: bold; line-height: 1.2em;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; font-weight: normal; line-height: 16px;"&gt;&lt;span class="Apple-style-span" style="font-size: 17px; font-weight: bold; line-height: 20px;"&gt;Using the code&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/h2&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;Let's introduce our class:&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; font-size: 10pt; line-height: 1.2em;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small; line-height: normal;"&gt;See full details:&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small; line-height: normal;"&gt;&lt;a href="http://www.codeproject.com/KB/WCF/cancelbutton_changelist.aspx" target="_blank"&gt;http://www.codeproject.com/KB/WCF/cancelbutton_changelist.aspx&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Related links&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2009/09/wcf-chat-sample.html"&gt;WCF  Chat Sample&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/implement-cancel-button-while-using.html"&gt;Implement  a Cancel button while using Bindings, and send only an object's changes to a WCF  service&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2011/05/send-cookies-when-making-wcf-service.html"&gt;Send  Cookies When Making WCF Service Calls&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2010/08/hosting-wcf-in-sharepoint-2010.html"&gt;Hosting  WCF in SharePoint 2010&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2010/03/wcf-architecture-overview.html"&gt;WCF  Architecture Overview&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2010/03/getting-started-tutorial.html"&gt;Getting  Started Tutorial&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2010/03/wcf-programming-for-beginners.html"&gt;WCF  programming for Beginners&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2010/02/returning-large-volume-of-records-from.html"&gt;Returning  Large Volume of Records from SOAP based WCF Service&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2009/11/windows-communication-foundation_26.html"&gt;Windows  Communication Foundation&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2009/11/windows-communication-foundation.html"&gt;Windows  Communication Foundation Architecture Overview&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2009/09/how-to-implement-asynchronous-service.html"&gt;How  to: Implement an Asynchronous Service Operation&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2009/09/windows-communication-foundation.html"&gt;Windows  Communication Foundation Architecture Overview&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2009/09/truely-simple-example-to-get-started.html"&gt;A  truely simple example to get started with WCF&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asp-net-csharp-vb.blogspot.com/2009/09/whats-new-for-wcf-in-visual-studio-2008.html"&gt;What's  New for WCF in Visual Studio 2008&lt;/a&gt;&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-806313348695701690?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/806313348695701690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=806313348695701690' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/806313348695701690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/806313348695701690'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/implement-cancel-button-while-using.html' title='Implement a Cancel button while using Bindings, and send only an object&apos;s changes to a WCF service'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-2697428301480330304</id><published>2011-05-10T05:52:00.000-07:00</published><updated>2011-05-10T05:52:13.164-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Send Cookies When Making WCF Service Calls</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, sans-serif; line-height: 16px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;h2 style="font-family: Verdana, Arial, sans-serif; font-weight: bold; line-height: 1.2em;"&gt;Introduction&lt;/h2&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;This article presents an example on how to send cookies when making WCF service calls.&lt;/div&gt;&lt;h2 style="font-family: Verdana, Arial, sans-serif; font-weight: bold; line-height: 1.2em;"&gt;Background&lt;/h2&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;Once in a while, you may find that you want to send some information in the form of "&lt;a href="http://en.wikipedia.org/wiki/HTTP_cookie" style="color: #004cd5; text-decoration: none;"&gt;Cookies&lt;/a&gt;" to the server when making WCF calls. For example, if the WCF service is protected by a "&lt;a href="http://support.microsoft.com/kb/910443" style="color: #004cd5; text-decoration: none;"&gt;Forms Authentication&lt;/a&gt;" mechanism, you will need to send the authentication cookie when making the WCF call to gain the required access to the service.&lt;/div&gt;&lt;ul&gt;&lt;li style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;If you are calling a "&lt;a href="http://en.wikipedia.org/wiki/Representational_State_Transfer" style="color: #004cd5; text-decoration: none;"&gt;REST&lt;/a&gt;" service using the "&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.80).aspx" style="color: #004cd5; text-decoration: none;"&gt;WebClient&lt;/a&gt;" class, this should not be a difficult task. You can simply work on the "&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.cookiecontainer.aspx" style="color: #004cd5; text-decoration: none;"&gt;CookieContainer&lt;/a&gt;" property of the "&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx" style="color: #004cd5; text-decoration: none;"&gt;HttpWebRequest&lt;/a&gt;" class.&lt;/li&gt;&lt;li style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;If you are calling a regular WCF service, and your client proxies are generated by the "&lt;a href="http://msdn.microsoft.com/en-us/library/bb628652.aspx" style="color: #004cd5; text-decoration: none;"&gt;Adding service reference&lt;/a&gt;" tool in the Visual Studio, the method to send cookies is not so obvious.&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;This article is to present an example on how to send cookies when making WCF calls using the Visual Studio generated client proxies.&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;img alt="SolutionExplorer.JPG" border="0" complete="true" height="561" hspace="0" src="http://www.codeproject.com/KB/WCF/WCFServiceCookie/SolutionExplorer.JPG" style="height: 561px; overflow-x: auto; overflow-y: auto; width: 344px;" width="344" /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: Verdana, Arial, sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, sans-serif;"&gt;The attached Visual Studio solution is developed in Visual Studio 2010. It has two projects:&lt;/div&gt;&lt;ul style="line-height: 16px;"&gt;&lt;li style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;The "&lt;code style="color: #990000; font: normal normal normal 11pt/normal 'Courier New', Courier, mono;"&gt;WCFHost&lt;/code&gt;" is a simple ASP.NET MVC project that hosts the example WCF service.&lt;/li&gt;&lt;li style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;The "&lt;code style="color: #990000; font: normal normal normal 11pt/normal 'Courier New', Courier, mono;"&gt;WCFClient&lt;/code&gt;" is a simple WPF project. I will show you how to send cookies when calling WCF services in this project.&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;Let us start by first taking a look at the WCF service.&lt;/div&gt;&lt;h2 style="font-family: Verdana, Arial, sans-serif; font-weight: bold; line-height: 1.2em;"&gt;The WCF Service&lt;/h2&gt;&lt;div style="font-family: Verdana, Arial, sans-serif; line-height: 1.2em;"&gt;The example WCF service is implemented in the "&lt;em&gt;ServiceWithCookies.svc.cs&lt;/em&gt;" file in the "&lt;code style="color: #990000; font: normal normal normal 11pt/normal 'Courier New', Courier, mono;"&gt;WCFHost&lt;/code&gt;" project.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;See full details:&amp;nbsp;&lt;a href="http://www.codeproject.com/KB/WCF/WCFServiceCookie.aspx" target="_blank"&gt;http://www.codeproject.com/KB/WCF/WCFServiceCookie.aspx&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-2697428301480330304?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/2697428301480330304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=2697428301480330304' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/2697428301480330304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/2697428301480330304'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/send-cookies-when-making-wcf-service.html' title='Send Cookies When Making WCF Service Calls'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-6928703502827447637</id><published>2011-05-09T11:47:00.000-07:00</published><updated>2011-05-09T11:51:10.266-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.net 4.0 new features'/><title type='text'>ASP.net 4.0 Ajax</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-weight: bold;"&gt;&lt;strong&gt;jQuery Included with Web Forms and MVC&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif;"&gt;The Visual Studio templates for both Web Forms and MVC include the open-source jQuery library. When you create a new website or project, a Scripts folder containing the following 3 files is created:&lt;/div&gt;&lt;ul style="font-family: Verdana, Helvetica, sans-serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 30px; padding-right: 0px; padding-top: 5px;"&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;jQuery-1.4.1.js – The human-readable, unminified version of the jQuery library.&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;jQuery-14.1.min.js – The minified version of the jQuery library.&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;jQuery-1.4.1-vsdoc.js – The Intellisense documentation file for the jQuery library.&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif;"&gt;Include the unminified version of jQuery while developing an application. Include the minified version of jQuery for production applications.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif;"&gt;For example, the following Web Forms page illustrates how you can use jQuery to change the background color of ASP.NET TextBox controls to yellow when they have focus.&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowjQuery.aspx.cs" Inherits="ShowjQuery" %&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;lt;head runat="server"&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;title&amp;gt;Show jQuery&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;form id="form1" runat="server"&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;asp:TextBox ID="txtFirstName" runat="server" /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;asp:TextBox ID="txtLastName" runat="server" /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script src="Scripts/jquery-1.4.1.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script type="text/javascript"&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$("input").focus( function() { $(this).css("background-color", "yellow"); });&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h2 style="margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;/h2&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; font-weight: normal; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;strong&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Content Delivery Network Support&lt;/span&gt;&lt;/strong&gt;&lt;/h2&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;The Microsoft Ajax Content Delivery Network (CDN) enables you to easily add ASP.NET Ajax and jQuery scripts to your Web applications. For example, you can start using the jQuery library simply by adding a&amp;nbsp;&lt;code style="color: #800039;"&gt;&lt;script&gt;&lt;/code&gt;&amp;nbsp;tag to your page that points to Ajax.microsoft.com like this:&lt;/font&gt;&lt;/p&gt;&lt;p style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif" size="3"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;code&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif" size="3"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&amp;lt;script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif" size="3"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;/code&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;p style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;By taking advantage of the Microsoft Ajax CDN, you can significantly improve the performance of your Ajax applications. The contents of the Microsoft Ajax CDN are cached on servers located around the world. In addition, the Microsoft Ajax CDN enables browsers to reuse cached JavaScript files for Web sites that are located in different domains.&lt;/font&gt;&lt;/p&gt;&lt;p style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;The Microsoft Ajax Content Delivery Network supports SSL (HTTPS) in case you need to serve a web page using the Secure Sockets Layer.&lt;/font&gt;&lt;/p&gt;&lt;p style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;To learn more about the Microsoft Ajax CDN, visit the following website:&lt;/font&gt;&lt;/p&gt;&lt;p style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal; margin-left: 20px; "&gt;&lt;a href="http://www.asp.net/ajaxlibrary/CDN.ashx" style="color: rgb(3, 78, 250); "&gt;&lt;font class="Apple-style-span" size="3"&gt;http://www.asp.net/ajaxlibrary/CDN.ashx&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;The ASP.NET ScriptManager supports the Microsoft Ajax CDN. Simply by setting one property, the EnableCdn property, you can retrieve all ASP.NET framework JavaScript files from the CDN:&lt;/font&gt;&lt;/p&gt;&lt;p style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif" size="3"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;code&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif" size="3"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&amp;lt;asp:ScriptManager ID="sm1" EnableCdn="true" runat="server" /&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif" size="3"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;/code&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif" size="3"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;After you set the EnableCdn property to the value true, the ASP.NET framework will retrieve all ASP.NET framework JavaScript files from the CDN including all JavaScript files used for validation and the UpdatePanel. Setting this one property can have a dramatic impact on the performance of your web application.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;You can set the CDN path for your own JavaScript files by using the WebResource attribute. The new CdnPath property specifies the path to the CDN used when you set the EnableCdn property to the value true:&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;pre class="code_block" style="padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 15px; display: block; white-space: pre; font-family: 'Courier New', Courier, monospace; font-weight: 400; overflow-x: scroll; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: rgb(128, 0, 57); "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;[assembly: WebResource("Foo.js", "application/x-javascript", CdnPath = "http://foo.com/foo/bar/foo.js")]&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;h2 style="font-weight: normal; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;a name="0.2__Toc253429253"&gt;&lt;/a&gt;&lt;a name="0.2__Toc243304627"&gt;&lt;/a&gt;&lt;strong&gt;ScriptManager Explicit Scripts&lt;/strong&gt;&lt;/font&gt;&lt;/font&gt;&lt;/h2&gt;&lt;p style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;In the past, if you used the ASP.NET ScriptManger then you were required to load the entire monolithic ASP.NET Ajax Library. By taking advantage of the new ScriptManager.AjaxFrameworkMode property, you can control exactly which components of the ASP.NET Ajax Library are loaded and load only the components of the ASP.NET Ajax Library that you need.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;The ScriptManager.AjaxFrameworkMode property can be set to the following values:&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;ul style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 30px; "&gt;&lt;li style="padding-top: 0.1em; padding-right: 0px; padding-bottom: 0.1em; padding-left: 0px; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;Enabled -- Specifies that the ScriptManager control automatically includes the MicrosoftAjax.js script file, which is a combined script file of every core framework script (legacy behavior).&lt;/font&gt;&lt;/font&gt;&lt;/li&gt;&lt;li style="padding-top: 0.1em; padding-right: 0px; padding-bottom: 0.1em; padding-left: 0px; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;Disabled -- Specifies that all Microsoft Ajax script features are disabled and that the ScriptManager control does not reference any scripts automatically.&lt;/font&gt;&lt;/font&gt;&lt;/li&gt;&lt;li style="padding-top: 0.1em; padding-right: 0px; padding-bottom: 0.1em; padding-left: 0px; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;Explicit -- Specifies that you will explicitly include script references to individual framework core script file that your page requires, and that you will include references to the dependencies that each script file requires.&lt;/font&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;For example, if you set the AjaxFrameworkMode property to the value Explicit then you can specify the particular ASP.NET Ajax component scripts that you need:&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;code&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&amp;lt;asp:ScriptManager ID="sm1" AjaxFrameworkMode="Explicit" runat="server"&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&amp;lt;Scripts&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;lt;asp:ScriptReference Name="MicrosoftAjaxCore.js" /&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;lt;asp:ScriptReference Name="MicrosoftAjaxComponentModel.js" /&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;lt;asp:ScriptReference Name="MicrosoftAjaxSerialization.js" /&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;lt;asp:ScriptReference Name="MicrosoftAjaxNetwork.js" /&amp;gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&amp;lt;/Scripts&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&amp;lt;/asp:ScriptManager&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;/code&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;div style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="font-weight: normal; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;font class="Apple-style-span" size="3"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="font-size: 0.7em; font-weight: normal; "&gt;&lt;font class="Apple-style-span" face="Verdana, Helvetica, sans-serif"&gt;&lt;/font&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif; font-size: 0.7em;"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/DIV&gt;&lt;/script&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-6928703502827447637?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/6928703502827447637/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=6928703502827447637' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/6928703502827447637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/6928703502827447637'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/aspnet-40-ajax.html' title='ASP.net 4.0 Ajax'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-1465306434719155635</id><published>2011-05-09T11:40:00.000-07:00</published><updated>2011-05-09T11:43:06.793-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.net 4.0 new features'/><title type='text'>ASP.net 4.0 Core Services</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif;"&gt;ASP.NET 4 introduces a number of features that improve core ASP.NET services such as output caching and session-state storage.&lt;/div&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304613"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429239"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc224729019"&gt;&lt;/a&gt;&lt;strong&gt;Web.config File&amp;nbsp;&lt;/strong&gt;&lt;strong&gt;Refactoring&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif;"&gt;The&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file that contains the configuration for a Web application has grown considerably over the past few releases of the .NET Framework as new features have been added, such as Ajax, routing, and integration with IIS 7. This has made it harder to configure or start new Web applications without a tool like Visual Studio. In .the NET Framework 4, the major configuration elements have been moved to the&amp;nbsp;&lt;code style="color: #800039;"&gt;machine.config&lt;/code&gt;&amp;nbsp;file, and applications now inherit these settings. This allows the&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file in ASP.NET 4 applications either to be empty or to contain just the following lines, which specify for Visual Studio what version of the framework the application is targeting:&lt;/div&gt;&lt;div style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;configuration&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;system.web&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;compilation targetFramework="4.0" /&amp;gt; &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/system.web&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/configuration&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;strong&gt;Extensible Output Caching&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;Since the time that ASP.NET 1.0 was released, output caching has enabled developers to store the generated output of pages, controls, and HTTP responses in memory. On subsequent Web requests, ASP.NET can serve content more quickly by retrieving the generated output from memory instead of regenerating the output from scratch. However, this approach has a limitation — generated content always has to be stored in memory, and on servers that are experiencing heavy traffic, the memory consumed by output caching can compete with memory demands from other portions of a Web application.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;ASP.NET 4 adds an extensibility point to output caching that enables you to configure one or more custom output-cache providers. Output-cache providers can use any storage mechanism to persist HTML content. This makes it possible to create custom output-cache providers for diverse persistence mechanisms, which can include local or remote disks, cloud storage, and distributed cache engines.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;You create a custom output-cache provider as a class that derives from the new&lt;em&gt;System.Web.Caching.OutputCacheProvider&lt;/em&gt;&amp;nbsp;type. You can then configure the provider in the&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file by using the new&amp;nbsp;&lt;em&gt;providers&lt;/em&gt;&amp;nbsp;subsection of the&amp;nbsp;&lt;em&gt;outputCache&amp;nbsp;&lt;/em&gt;element, as shown in the following example:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;caching&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;outputCache defaultProvider="AspNetInternalProvider"&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;providers&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;add name="DiskCache"&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type="Test.OutputCacheEx.DiskOutputCacheProvider, DiskCacheProvider"/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/providers&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/outputCache&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;/caching&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;By default in ASP.NET 4, all HTTP responses, rendered pages, and controls use the in-memory output cache, as shown in the previous example, where the&amp;nbsp;&lt;em&gt;defaultProvider&lt;/em&gt;&amp;nbsp;attribute is set to AspNetInternalProvider. You can change the default output-cache provider used for a Web application by specifying a different provider name for&lt;em&gt;defaultProvider&lt;/em&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;In addition, you can select different output-cache providers per control and per request. The easiest way to choose a different output-cache provider for different Web user controls is to do so declaratively by using the new&amp;nbsp;&lt;em&gt;providerName&lt;/em&gt;&amp;nbsp;attribute in a control directive, as shown in the following example:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;%@ OutputCache Duration="60" VaryByParam="None" providerName="DiskCache" %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;Specifying a different output cache provider for an HTTP request requires a little more work. Instead of declaratively specifying the provider, you override the new&amp;nbsp;&lt;em&gt;GetOuputCacheProviderName&lt;/em&gt;&amp;nbsp;method in the&lt;code style="color: #800039;"&gt;Global.asax&lt;/code&gt;&amp;nbsp;file to programmatically specify which provider to use for a specific request. The following example shows how to do this.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;public override string GetOutputCacheProviderName(HttpContext context)&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (context.Request.Path.EndsWith("Advanced.aspx"))&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "DiskCache";&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return base.GetOutputCacheProviderName(context);&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;With the addition of output-cache provider extensibility to ASP.NET 4, you can now pursue more aggressive and more intelligent output-caching strategies for your Web sites. For example, it is now possible to cache the "Top 10" pages of a site in memory, while caching pages that get lower traffic on disk. Alternatively, you can cache every vary-by combination for a rendered page, but use a distributed cache so that the memory consumption is offloaded from front-end Web servers.&lt;/span&gt;&lt;/div&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc224729020"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429241"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304615"&gt;&lt;/a&gt;&lt;strong&gt;Auto-Start Web Applications&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;Some Web applications need to load large amounts of data or perform expensive initialization processing before serving the first request. In earlier versions of ASP.NET, for these situations you had to devise custom approaches to "wake up" an ASP.NET application and then run initialization code during the&amp;nbsp;&lt;em&gt;Application_Load&lt;/em&gt;method in the&amp;nbsp;&lt;code style="color: #800039;"&gt;Global.asax&lt;/code&gt;&amp;nbsp;file.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;A new scalability feature named&amp;nbsp;&lt;em&gt;auto-star&lt;/em&gt;t that directly addresses this scenario is available when ASP.NET 4 runs on IIS 7.5 on Windows Server 2008 R2. The auto-start feature provides a controlled approach for starting up an application pool, initializing an ASP.NET application, and then accepting HTTP requests.&lt;/span&gt;&lt;/div&gt;&lt;div class="note" style="background-color: #eeeeee; border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 2px; border-left-color: black; border-left-style: solid; border-left-width: 2px; border-right-color: black; border-right-style: solid; border-right-width: 2px; border-top-color: black; border-top-style: solid; border-top-width: 2px; margin-bottom: 10px; margin-left: 10px; margin-right: 10px; margin-top: 10px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;strong&gt;IIS Application Warm-Up Module for IIS 7.5&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;The IIS team has released the first beta test version of the Application Warm-Up Module for IIS 7.5. This makes warming up your applications even easier than previously described. Instead of writing custom code, you specify the URLs of resources to execute before the Web application accepts requests from the network. This warm-up occurs during startup of the IIS service (if you configured the IIS application pool as&amp;nbsp;&lt;em&gt;AlwaysRunning&lt;/em&gt;) and when an IIS worker process recycles. During recycle, the old IIS worker process continues to execute requests until the newly spawned worker process is fully warmed up, so that applications experience no interruptions or other issues due to unprimed caches. Note that this module works with any version of ASP.NET, starting with version 2.0.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;For more information, see&amp;nbsp;&lt;a href="http://www.iis.net/extensions/applicationwarmup%20on%20the%20IIS.net" style="color: #034efa;" target="_blank"&gt;Application Warm-Up&lt;/a&gt;&amp;nbsp;on the IIS.net Web site. For a walkthrough that illustrates how to use the warm-up feature, see&amp;nbsp;&lt;a href="http://learn.iis.net/page.aspx/688/getting-started-with-the-iis-75-application-warm-up-module/" style="color: #034efa;" target="_blank"&gt;Getting Started with the IIS 7.5 Application Warm-Up Module&lt;/a&gt;&amp;nbsp;on the IIS.net Web site.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;To use the auto-start feature, an IIS administrator sets an application pool in IIS 7.5 to be automatically started by using the following configuration in the&amp;nbsp;&lt;code style="color: #800039;"&gt;applicationHost.config&lt;/code&gt;&amp;nbsp;file:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;applicationpools&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;add name="MyApplicationPool" startMode="AlwaysRunning" /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;/applicationpools&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;Because a single application pool can contain multiple applications, you specify individual applications to be automatically started by using the following configuration in the&amp;nbsp;&lt;code style="color: #800039;"&gt;applicationHost.config&lt;/code&gt;&amp;nbsp;file:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;sites&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;site name="MySite" id="1"&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application path="/" &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;serviceAutoStartEnabled="true"&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;serviceAutoStartProvider="PrewarmMyCache" &amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!-- Additional content --&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/site&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;/sites&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;!-- Additional content --&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;serviceautostartproviders&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;add name="PrewarmMyCache"&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type="MyNamespace.CustomInitialization, MyLibrary" /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;/serviceautostartproviders&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;When an IIS 7.5 server is cold-started or when an individual application pool is recycled, IIS 7.5 uses the information in the&amp;nbsp;&lt;code style="color: #800039;"&gt;applicationHost.config&lt;/code&gt;&amp;nbsp;file to determine which Web applications need to be automatically started. For each application that is marked for auto-start, IIS7.5 sends a request to ASP.NET 4 to start the application in a state during which the application temporarily does not accept HTTP requests. When it is in this state, ASP.NET instantiates the type defined by the&amp;nbsp;&lt;em&gt;serviceAutoStartProvider&lt;/em&gt;&amp;nbsp;attribute (as shown in the previous example) and calls into its public entry point.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;You create a managed auto-start type with the necessary entry point by implementing the&lt;em&gt;IProcessHostPreloadClient&lt;/em&gt;&amp;nbsp;interface, as shown in the following example:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;public class CustomInitialization : System.Web.Hosting.IProcessHostPreloadClient&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;public void Preload(string[] parameters)&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Perform initialization. &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;After your initialization code runs in the&amp;nbsp;&lt;em&gt;Preload&lt;/em&gt;&amp;nbsp;method and the method returns, the ASP.NET application is ready to process requests.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;With the addition of auto-start to IIS .5 and ASP.NET 4, you now have a well-defined approach for performing expensive application initialization prior to processing the first HTTP request. For example, you can use the new auto-start feature to initialize an application and then signal a load-balancer that the application was initialized and ready to accept HTTP traffic.&lt;/span&gt;&lt;/div&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc224729021"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429242"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304616"&gt;&lt;/a&gt;&lt;strong&gt;Permanently Redirecting a Page&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;It is common practice in Web applications to move pages and other content around over time, which can lead to an accumulation of stale links in search engines. In ASP.NET, developers have traditionally handled requests to old URLs by using by using the&amp;nbsp;&lt;em&gt;Response.Redirect&lt;/em&gt;&amp;nbsp;method to forward a request to the new URL. However, the&lt;em&gt;Redirect&lt;/em&gt;&amp;nbsp;method issues an HTTP 302 Found (temporary redirect) response, which results in an extra HTTP round trip when users attempt to access the old URLs.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;ASP.NET 4 adds a new&amp;nbsp;&lt;em&gt;RedirectPermanent&lt;/em&gt;&amp;nbsp;helper method that makes it easy to issue HTTP 301 Moved Permanently responses, as in the following example:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre class="code_block" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #800039; display: block; font-family: 'Courier New', Courier, monospace; font-weight: 400; margin-bottom: 0px; margin-left: 15px; margin-right: 10px; margin-top: 0px; overflow-x: scroll; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px; white-space: pre;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;RedirectPermanent("/newpath/foroldcontent.aspx");       &lt;br /&gt;    &lt;/span&gt;&lt;/pre&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;Search engines and other user agents that recognize permanent redirects will store the new URL that is associated with the content, which eliminates the unnecessary round trip made by the browser for temporary redirects.&lt;/span&gt;&lt;/div&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc224729022"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429243"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304617"&gt;&lt;/a&gt;&lt;strong&gt;Shrinking Session State&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;ASP.NET provides two default options for storing session state across a Web farm: a session-state provider that invokes an out-of-process session-state server, and a session-state provider that stores data in a Microsoft SQL Server database. Because both options involve storing state information outside a Web application's worker process, session state has to be serialized before it is sent to remote storage. Depending on how much information a developer saves in session state, the size of the serialized data can grow quite large.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;ASP.NET 4 introduces a new compression option for both kinds of out-of-process session-state providers. When the&amp;nbsp;&lt;em&gt;compressionEnabled&lt;/em&gt;&amp;nbsp;configuration option shown in the following example is set to&amp;nbsp;&lt;em&gt;true&lt;/em&gt;, ASP.NET will compress (and decompress) serialized session state by using the .NET Framework&lt;em&gt;System.IO.Compression.GZipStream&lt;/em&gt;&amp;nbsp;class.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;sessionState&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;mode="SqlServer"&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;sqlConnectionString="data source=dbserver;Initial Catalog=aspnetstate"&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;allowCustomSqlDatabase="true"&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;compressionEnabled="true"&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;With the simple addition of the new attribute to the&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file, applications with spare CPU cycles on Web servers can realize substantial reductions in the size of serialized session-state data.&lt;/span&gt;&lt;/div&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429244"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304618"&gt;&lt;/a&gt;&lt;strong&gt;Expanding the Range of Allowable URLs&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;ASP.NET 4 introduces new options for expanding the size of application URLs. Previous versions of ASP.NET constrained URL path lengths to 260 characters, based on the NTFS file-path limit. In ASP.NET 4, you have the option to increase (or decrease) this limit as appropriate for your applications, using two new&amp;nbsp;&lt;em&gt;httpRuntime&lt;/em&gt;configuration attributes. The following example shows these new attributes.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;httpRuntime maxRequestPathLength="260" maxQueryStringLength="2048" /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;To allow longer or shorter paths (the portion of the URL that does not include protocol, server name, and query string), modify the&amp;nbsp;&lt;em&gt;maxRequestPathLength&lt;/em&gt;&amp;nbsp;attribute. To allow longer or shorter query strings, modify the value of the&amp;nbsp;&lt;em&gt;maxQueryStringLength&lt;/em&gt;&amp;nbsp;attribute.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;ASP.NET 4 also enables you to configure the characters that are used by the URL character check. When ASP.NET finds an invalid character in the path portion of a URL, it rejects the request and issues an HTTP 400 error. In previous versions of ASP.NET, the URL character checks were limited to a fixed set of characters. In ASP.NET 4, you can customize the set of valid characters using the new&amp;nbsp;&lt;em&gt;requestPathInvalidChars&lt;/em&gt;&amp;nbsp;attribute of the&lt;em&gt;httpRuntime&lt;/em&gt;&amp;nbsp;configuration element, as shown in the following example:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;httpRuntime requestPathInvalidChars="&amp;lt;,&amp;gt;,*,%,&amp;amp;,:,\,?"&amp;nbsp;&amp;nbsp;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;By default, the&amp;nbsp;&lt;em&gt;requestPathInvalidChars&lt;/em&gt;&amp;nbsp;attribute defines eight characters as invalid. (In the string that is assigned to&amp;nbsp;&lt;em&gt;requestPathInvalidChars&lt;/em&gt;&amp;nbsp;by default&lt;em&gt;,&amp;nbsp;&lt;/em&gt;the less than (&amp;lt;), greater than (&amp;gt;), and ampersand (&amp;amp;) characters are encoded, because the&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file is an XML file.) You can customize the set of invalid characters as needed.&lt;/span&gt;&lt;/div&gt;&lt;div class="note" style="background-color: #eeeeee; border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 2px; border-left-color: black; border-left-style: solid; border-left-width: 2px; border-right-color: black; border-right-style: solid; border-right-width: 2px; border-top-color: black; border-top-style: solid; border-top-width: 2px; margin-bottom: 10px; margin-left: 10px; margin-right: 10px; margin-top: 10px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;strong&gt;Note&amp;nbsp;&lt;/strong&gt;ASP.NET 4 always rejects URL paths that contain characters in the ASCII range of 0x00 to 0x1F, because those are invalid URL characters as defined in RFC 2396 of the IETF (&lt;a href="http://www.ietf.org/rfc/rfc2396.txt" style="color: #034efa;" target="_blank"&gt;http://www.ietf.org/rfc/rfc2396.txt&lt;/a&gt;). On versions of Windows Server that run IIS 6 or higher, the http.sys protocol device driver automatically rejects URLs with these characters.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429245"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304619"&gt;&lt;/a&gt;&lt;strong&gt;Extensible Request Validation&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;ASP.NET request validation searches incoming HTTP request data for strings that are commonly used in cross-site scripting (XSS) attacks. If potential XSS strings are found, request validation flags the suspect string and returns an error. The built-in request validation returns an error only when it finds the most common strings used in XSS attacks. Previous attempts to make the XSS validation more aggressive resulted in too many false positives. However, customers might want request validation that is more aggressive, or conversely might want to intentionally relax XSS checks for specific pages or for specific types of requests.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;In ASP.NET 4, the request validation feature has been made extensible so that you can use custom request-validation logic. To extend request validation, you create a class that derives from the new&lt;em&gt;System.Web.Util.RequestValidator&amp;nbsp;&lt;/em&gt;type, and you configure the application (in the&amp;nbsp;&lt;em&gt;httpRuntime&lt;/em&gt;&amp;nbsp;section of the&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file) to use the custom type. The following example shows how to configure a custom request-validation class:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;httpRuntime requestValidationType="Samples.MyValidator, Samples" /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;The new&amp;nbsp;&lt;em&gt;requestValidationType&lt;/em&gt;&amp;nbsp;attribute requires a standard .NET Framework type identifier string that specifies the class that provides custom request validation. For each request, ASP.NET invokes the custom type to process each piece of incoming HTTP request data. The incoming URL, all the HTTP headers (both cookies and custom headers), and the entity body are all available for inspection by a custom request validation class like that shown in the following example:&lt;/span&gt;&lt;/div&gt;&lt;pre class="code_block" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #800039; display: block; font-family: 'Courier New', Courier, monospace; font-weight: 400; margin-bottom: 0px; margin-left: 15px; margin-right: 10px; margin-top: 0px; overflow-x: scroll; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px; white-space: pre;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;public class CustomRequestValidation : RequestValidator&lt;br /&gt;{&lt;br /&gt;  protected override bool IsValidRequestString(&lt;br /&gt;      HttpContext context, string value, &lt;br /&gt;      RequestValidationSource requestValidationSource, &lt;br /&gt;      string collectionKey, &lt;br /&gt;      out int validationFailureIndex) &lt;br /&gt;    {...}&lt;br /&gt; }&lt;br /&gt;    &lt;/span&gt;&lt;/pre&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;For cases where you do not want to inspect a piece of incoming HTTP data, the request-validation class can fall back to let the ASP.NET default request validation run by simply calling&amp;nbsp;&lt;em&gt;base.IsValidRequestString.&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429246"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304620"&gt;&lt;/a&gt;&lt;strong&gt;Object Caching and Object Caching Extensibility&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;Since its first release, ASP.NET has included a powerful in-memory object cache (&lt;em&gt;System.Web.Caching.Cache&lt;/em&gt;). The cache implementation has been so popular that it has been used in non-Web applications. However, it is awkward for a Windows Forms or WPF application to include a reference to&amp;nbsp;&lt;code style="color: #800039;"&gt;System.Web.dll&lt;/code&gt;&amp;nbsp;just to be able to use the ASP.NET object cache.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;To make caching available for all applications, the .NET Framework 4 introduces a new assembly, a new namespace, some base types, and a concrete caching implementation. The new&amp;nbsp;&lt;code style="color: #800039;"&gt;System.Runtime.Caching.dll&lt;/code&gt;assembly contains a new caching API in the&amp;nbsp;&lt;em&gt;System.Runtime.Caching&lt;/em&gt;&amp;nbsp;namespace. The namespace contains two core sets of classes:&lt;/span&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 30px; padding-right: 0px; padding-top: 5px;"&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;Abstract types that provide the foundation for building any type of custom cache implementation.&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;A concrete in-memory object cache implementation (the&amp;nbsp;&lt;em&gt;System.Runtime.Caching.MemoryCache&amp;nbsp;&lt;/em&gt;class).&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;The new&amp;nbsp;&lt;em&gt;MemoryCache&lt;/em&gt;&amp;nbsp;class is modeled closely on the ASP.NET cache, and it shares much of the internal cache engine logic with ASP.NET. Although the public caching APIs in&amp;nbsp;&lt;em&gt;System.Runtime.Caching&lt;/em&gt;&amp;nbsp;have been updated to support development of custom caches, if you have used the ASP.NET&amp;nbsp;&lt;em&gt;Cache&lt;/em&gt;&amp;nbsp;object, you will find familiar concepts in the new APIs.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;An in-depth discussion of the new&amp;nbsp;&lt;em&gt;MemoryCache&lt;/em&gt;&amp;nbsp;class and supporting base APIs would require an entire document. However, the following example gives you an idea of how the new cache API works. The example was written for a Windows Forms application, without any dependency on&amp;nbsp;&lt;code style="color: #800039;"&gt;System.Web.dll&lt;/code&gt;.&lt;/span&gt;&lt;/div&gt;&lt;pre class="code_block" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #800039; display: block; font-family: 'Courier New', Courier, monospace; font-weight: 400; margin-bottom: 0px; margin-left: 15px; margin-right: 10px; margin-top: 0px; overflow-x: scroll; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px; white-space: pre;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;private void btnGet_Click(object sender, EventArgs e) &lt;br /&gt;{ &lt;br /&gt;  //Obtain a reference to the default MemoryCache instance. &lt;br /&gt;  //Note that you can create multiple MemoryCache(s) inside &lt;br /&gt;  //of a single application. &lt;br /&gt;  ObjectCache cache = MemoryCache.Default; &lt;br /&gt;  &lt;br /&gt;  //In this example the cache is storing the contents of a file string &lt;br /&gt;  fileContents = cache["filecontents"] as string;&lt;br /&gt;  &lt;br /&gt;  //If the file contents are not currently in the cache, then &lt;br /&gt;  //the contents are read from disk and placed in the cache. &lt;br /&gt;  if (fileContents == null) &lt;br /&gt;  {&lt;br /&gt;    //A CacheItemPolicy object holds all the pieces of cache &lt;br /&gt;    //dependency and cache expiration metadata related to a single &lt;br /&gt;    //cache entry. &lt;br /&gt;    CacheItemPolicy policy = new CacheItemPolicy(); &lt;br /&gt;    &lt;br /&gt;    //Build up the information necessary to create a file dependency. &lt;br /&gt;    //In this case we just need the file path of the file on disk. &lt;br /&gt;    List filePaths = new List(); &lt;br /&gt;    filePaths.Add("c:\\data.txt"); &lt;br /&gt;    &lt;br /&gt;    //In the new cache API, dependencies are called "change monitors". &lt;br /&gt;    //For this example we want the cache entry to be automatically expired &lt;br /&gt;    //if the contents on disk change. A HostFileChangeMonitor provides &lt;br /&gt;    //this functionality. &lt;br /&gt;    policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); &lt;br /&gt;    &lt;br /&gt;    //Fetch the file's contents &lt;br /&gt;    fileContents = File.ReadAllText("c:\\data.txt"); &lt;br /&gt;    &lt;br /&gt;    //And then store the file's contents in the cache &lt;br /&gt;    cache.Set("filecontents", fileContents, policy); &lt;br /&gt;    &lt;br /&gt;  } &lt;br /&gt;  MessageBox.Show(fileContents); &lt;br /&gt;} &lt;br /&gt;   &lt;br /&gt;    &lt;/span&gt;&lt;/pre&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429247"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304621"&gt;&lt;/a&gt;&lt;strong&gt;Extensible HTML, URL, and HTTP Header Encoding&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;In ASP.NET 4, you can create custom encoding routines for the following common text-encoding tasks:&lt;/span&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 30px; padding-right: 0px; padding-top: 5px;"&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;HTML encoding.&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;URL encoding.&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;HTML attribute encoding.&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;Encoding outbound HTTP headers.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;You can create a custom encoder by deriving from the new&amp;nbsp;&lt;em&gt;System.Web.Util.HttpEncoder&lt;/em&gt;&amp;nbsp;type and then configuring ASP.NET to use the custom type in the&amp;nbsp;&lt;em&gt;httpRuntime&lt;/em&gt;&amp;nbsp;section of the&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file, as shown in the following example:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;httpRuntime encoderType="Samples.MyCustomEncoder, Samples" /&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;After a custom encoder has been configured, ASP.NET automatically calls the custom encoding implementation whenever public encoding methods of the&amp;nbsp;&lt;em&gt;System.Web.HttpUtility&lt;/em&gt;&amp;nbsp;or&amp;nbsp;&lt;em&gt;System.Web.HttpServerUtility&lt;/em&gt;&amp;nbsp;classes are called. This lets one part of a Web development team create a custom encoder that implements aggressive character encoding, while the rest of the Web development team continues to use the public ASP.NET encoding APIs. By centrally configuring a custom encoder in the&amp;nbsp;&lt;em&gt;httpRuntime&amp;nbsp;&lt;/em&gt;element, you are guaranteed that all text-encoding calls from the public ASP.NET encoding APIs are routed through the custom encoder.&lt;/span&gt;&lt;/div&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429248"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304622"&gt;&lt;/a&gt;&lt;strong&gt;Performance Monitoring for Individual Applications in a Single Worker Process&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;In order to increase the number of Web sites that can be hosted on a single server, many hosters run multiple ASP.NET applications in a single worker process. However, if multiple applications use a single shared worker process, it is difficult for server administrators to identify an individual application that is experiencing problems.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;ASP.NET 4 leverages new resource-monitoring functionality introduced by the CLR. To enable this functionality, you can add the following XML configuration snippet to the&amp;nbsp;&lt;code style="color: #800039;"&gt;aspnet.config&lt;/code&gt;&amp;nbsp;configuration file.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8" ?&amp;gt; &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;configuration&amp;gt; &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;runtime&amp;gt; &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;appDomainResourceMonitoring enabled="true"/&amp;gt; &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/runtime&amp;gt; &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="note" style="background-color: #eeeeee; border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 2px; border-left-color: black; border-left-style: solid; border-left-width: 2px; border-right-color: black; border-right-style: solid; border-right-width: 2px; border-top-color: black; border-top-style: solid; border-top-width: 2px; margin-bottom: 10px; margin-left: 10px; margin-right: 10px; margin-top: 10px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;strong&gt;Note&amp;nbsp;&lt;/strong&gt;The&amp;nbsp;&lt;code style="color: #800039;"&gt;aspnet.config&lt;/code&gt;&amp;nbsp;file is in the directory where the .NET Framework is installed. It is not the&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;When the&amp;nbsp;&lt;em&gt;appDomainResourceMonitoring&lt;/em&gt;&amp;nbsp;feature has been enabled, two new performance counters are available in the "ASP.NET Applications" performance category:&amp;nbsp;&lt;em&gt;% Managed Processor Time&lt;/em&gt;&amp;nbsp;and&amp;nbsp;&lt;em&gt;Managed Memory Used&lt;/em&gt;. Both of these performance counters use the new CLR application-domain resource management feature to track estimated CPU time and managed memory utilization of individual ASP.NET applications. As a result, with ASP.NET 4, administrators now have a more granular view into the resource consumption of individual applications running in a single worker process.&lt;/span&gt;&lt;/div&gt;&lt;h2 style="font-family: Arial, Helvetica, sans-serif; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 5px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif; font-size: small;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc253429249"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7328185059134214054&amp;amp;postID=1465306434719155635" name="0.2__Toc243304623"&gt;&lt;/a&gt;&lt;strong&gt;Multi-Targeting&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;You can create an application that targets a specific version of the .NET Framework. In ASP.NET 4, a new attribute in the&amp;nbsp;&lt;em&gt;compilation&lt;/em&gt;&amp;nbsp;element of the&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file lets you target the .NET Framework 4 and later. If you explicitly target the .NET Framework 4, and if you include optional elements in the&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file such as the entries for&amp;nbsp;&lt;em&gt;system.codedom&lt;/em&gt;, these elements must be correct for the .NET Framework 4. (If you do not explicitly target the .NET Framework 4, the target framework is inferred from the lack of an entry in the&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file.)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;The following example shows the use of the&amp;nbsp;&lt;em&gt;targetFramework&lt;/em&gt;&amp;nbsp;attribute in the&amp;nbsp;&lt;em&gt;compilation&lt;/em&gt;&amp;nbsp;element of the&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&amp;lt;compilation targetFramework="4.0"/&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;Note the following about targeting a specific version of the .NET Framework:&lt;/span&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 30px; padding-right: 0px; padding-top: 5px;"&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;In a .NET Framework 4 application pool, the ASP.NET build system assumes the .NET Framework 4 as a target if the&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file does not include the&amp;nbsp;&lt;em&gt;targetFramework&lt;/em&gt;&amp;nbsp;attribute or if the&amp;nbsp;&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file is missing. (You might have to make coding changes to your application to make it run under the .NET Framework 4.)&lt;/span&gt;&lt;/li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;If you do include the&amp;nbsp;&lt;em&gt;targetFramework&lt;/em&gt;&amp;nbsp;attribute, and if the&amp;nbsp;&lt;em&gt;system.codeDom&lt;/em&gt;&amp;nbsp;element is defined in the&lt;code style="color: #800039;"&gt;Web.config&lt;/code&gt;&amp;nbsp;file, this file must contain the correct entries for the .NET Framework 4.&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;If you are using the&amp;nbsp;&lt;em&gt;aspnet_compiler&lt;/em&gt;&amp;nbsp;command to precompile your application (such as in a build environment), you must use the correct version of the&amp;nbsp;&lt;em&gt;aspnet_compiler&lt;/em&gt;&amp;nbsp;command for the target framework. Use the compiler that shipped with the .NET Framework 2.0 (%WINDIR%\Microsoft.NET\Framework\v2.0.50727) to compile for the .NET Framework 3.5 and earlier versions. Use the compiler that ships with the .NET Framework 4 to compile applications created using that framework or using later versions.&lt;/li&gt;&lt;li style="padding-bottom: 0.1em; padding-left: 0px; padding-right: 0px; padding-top: 0.1em;"&gt;At run time, the compiler uses the latest framework assemblies that are installed on the computer (and therefore in the GAC). If an update is made later to the framework (for example, a hypothetical version 4.1 is installed), you will be able to use features in the newer version of the framework even though the&lt;em&gt;targetFramework&lt;/em&gt;&amp;nbsp;attribute targets a lower version (such as 4.0). (However, at design time in Visual Studio 2010 or when you use the&amp;nbsp;&lt;em&gt;aspnet_compiler&lt;/em&gt;&amp;nbsp;command, using newer features of the framework will cause compiler errors).&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-1465306434719155635?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/1465306434719155635/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=1465306434719155635' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/1465306434719155635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/1465306434719155635'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/aspnet-40-core-services.html' title='ASP.net 4.0 Core Services'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-5500721364650627784</id><published>2011-05-08T15:44:00.000-07:00</published><updated>2011-05-08T15:45:09.671-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='URL Rewriting'/><title type='text'>ASP.NET URL Rewriting with HttpHandler</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Most of the time when we start learning something or doing something we get the first question that how does it helps? Or where I can use in the&amp;nbsp;real world?&lt;br /&gt;&lt;br /&gt;Same thing goes in this technique as well. What are URL rewriting first of all then what is routing engine? Let us see some real issues in our code.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;A. Case 1&lt;/b&gt;&lt;br /&gt;One day you had a URL book marked as Http://abc.com/main/1.aspx. But now it is moved to Http://xyz.com/main/1.aspx, will it work now, no. But as a web site developer or architect how you will manages these kinds of broken links in web sites.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;B. Case 2&lt;br /&gt;&lt;/b&gt;Suppose we have two servers where each server has hosted with 50 pages. But all the links have to be made available for both web sites. How do we handle this situation?&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C. Case 3&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;A website restructuring caused all of the Web pages in the /Admin/ directory to be moved to a /finance/Admin/ directory, you would want to use URL rewriting to check if a Web request was intended for a file in the /Admin/ directory. The request automatically should redirect the request to the same file, but in the /finance/Admin/ directory instead.&lt;br /&gt;&lt;br /&gt;And there are many more, so how do we handle all these scenarios. In classic ASP ages, it was very difficult to handle these scenarios, where we suppose to play with the ISAPI filters. Off course some third party software's. In ASP.NET Http Modules to handle all these using URL Rewriting as an another option.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;I. ASP.NET URL Rewriting&lt;/b&gt;&lt;br /&gt;By using URL rewriting, we can intercept an incoming Web request and redirecting the request to a different resource page. When performing URL rewriting, typically the URL being requested is checked and, based on its value, the request is redirected to a different URL.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Please refer to my last post for what happens when request comes to IIS or Scott Mitchell blogs or books from Dino Esposito you will really love them. And it is must to understand this post.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;II. Implementing URL Rewriting&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;In olden days URL rewriting was implemented with ISAPI filters at the IIS Web server level or some third party software's, which we are not going talk here. Our main focus is how to implement in ASP.NET. So, in ASP.NET URL rewriting can be implemented by using HTTP modules at the ASP.NET level.&lt;br /&gt;&lt;br /&gt;Using Http Modules by utilize the HttpContext object RewritePath () method. Here I am not going to explain the HttpApplication or HttpContext assuming that you have read my last post. But can tell one thing that; HttpContext class contains information about a specific HTTP request that is received by the IIS. An HttpContext instance is created for that request. This object contains properties to access the intrinsic object like Request, Response which in turn access to Application, Session and User objects.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;III. URL Rewriting with Built in HTTP Modules&lt;/b&gt;&lt;br /&gt;We can use out of the box Http Modules to perform the URL rewriting. Let us understand what are they and which event they are tied to in IHttpHandler. Let us see some of the out of the modules that we use day to day, yes we are working with the models, don't say that I never worked on Http Modules.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;1. FormsAuthenticationModule&lt;/b&gt;&lt;br /&gt;This module sets the identity of the user (to an IPrincipal) in the HttpContext for an ASP.NET application when forms authentication is enabled. FormsAuthenticationModule exposes AuthenticateRequest event. Where we can check the user is authenticated or not. If not redirect to a login page. Usually what we do use is Response.Redirect() but Context.RewritePath() method is also good option&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;FormsAuthentication_OnAuthenticate(&lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;nbsp;sender, FormsAuthenticationEventArgs args)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&amp;nbsp;(FormsAuthentication.Authenticate(&lt;span style="color: #a31515;"&gt;"a"&lt;/span&gt;,&amp;nbsp;&lt;span style="color: #a31515;"&gt;"a"&lt;/span&gt;) !=&amp;nbsp;&lt;span style="color: blue;"&gt;true&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Context.RewritePath(&lt;span style="color: #a31515;"&gt;"WebForm2.aspx"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;span style="line-height: 14px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So how we implement in HttpModule is&lt;br /&gt;&lt;span style="color: blue;"&gt;namespace&lt;/span&gt;&amp;nbsp;Chinna.SampleModules&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;SampleModule&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style="color: #2b91af;"&gt;IHttpModule&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;Dispose()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;Init(&lt;span style="color: #2b91af;"&gt;HttpApplication&lt;/span&gt;&amp;nbsp;context)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.AuthorizeRequest +=&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;EventHandler&lt;/span&gt;(OnAuthorizeRequest);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;OnAuthenticate(&lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;nbsp;sender,&amp;nbsp;&lt;span style="color: #2b91af;"&gt;EventArgs&lt;/span&gt;&amp;nbsp;e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;HttpApplication&lt;/span&gt;&amp;nbsp;app = (&lt;span style="color: #2b91af;"&gt;HttpApplication&lt;/span&gt;)sender;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; app.Context.RewritePath(&lt;span style="color: #a31515;"&gt;"WebForm1.aspx"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;b&gt;2. FileAuthorizationMoudle&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;When using Windows authentication, This HTTP module checks to ensure that the user account has adequate rights for the resource requested, and provides authorization services against file-system access-control lists (ACLs). Check the following code&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;IntPtr&lt;/span&gt;&amp;nbsp;userToken = System.Security.Principal.&lt;span style="color: #2b91af;"&gt;WindowsIdentity&lt;/span&gt;.GetCurrent().Token;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&amp;nbsp;(FileAuthorizationModule.CheckFileAccessForUser(&lt;span style="color: #a31515;"&gt;"~/WebForm1.aspx"&lt;/span&gt;, userToken,&amp;nbsp;&lt;span style="color: #a31515;"&gt;"GET"&lt;/span&gt;) ==&amp;nbsp;&lt;span style="color: blue;"&gt;true&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Write(&lt;span style="color: #a31515;"&gt;"You have access !!"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;else&lt;/span&gt;&lt;span style="line-height: 14px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Context.RewritePath(&lt;span style="color: #a31515;"&gt;"WebForm2.aspx"&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So how we implement in HttpModule is&lt;br /&gt;&lt;span style="color: blue;"&gt;namespace&lt;/span&gt;&amp;nbsp;Chinna.SampleModules&lt;br /&gt;{&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;SampleModule&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style="color: #2b91af;"&gt;IHttpModule&lt;/span&gt;{&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;Dispose()&lt;br /&gt;{}&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;Init(&lt;span style="color: #2b91af;"&gt;HttpApplication&lt;/span&gt;&amp;nbsp;context)&lt;br /&gt;{&lt;br /&gt;context.AuthorizeRequest +=&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;EventHandler&lt;/span&gt;(OnAuthorizeRequest); }&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;OnAuthorizeRequest(&lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;nbsp;sender,&amp;nbsp;&lt;span style="color: #2b91af;"&gt;EventArgs&lt;/span&gt;&amp;nbsp;e)&lt;br /&gt;{&lt;span style="color: #2b91af;"&gt;HttpApplication&lt;/span&gt;&amp;nbsp;app = (&lt;span style="color: #2b91af;"&gt;HttpApplication&lt;/span&gt;)sender;&lt;br /&gt;app.Context.RewritePath(&lt;span style="color: #a31515;"&gt;"WebForm1.aspx"&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;}&lt;span style="line-height: 14px;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;3. UrlAuthorizationModule&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The UrlAuthorizationModule determines whether the current user is permitted access to the requested URL. You can allow or deny a user or a role using allow or deny subelements in Authorization config element in the web.config, respectively.&lt;br /&gt;&lt;br /&gt;Allow and deny subelements are interpreted in the order they appear in the configuration. Once an element specifies that access is allowed or denied, the UrlAuthorizationModule completes its authorization check. For example, the following authorization section from a Web.config file requires users to log on (by denying anonymous users), and then allows only users in the Administrators role to have access. Users not in the Administrators role are denied.&lt;br /&gt;&lt;br /&gt;For example: The following code example grants access to Chinna and members of the Admins role, while denying it to Rick and all anonymous users.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;See full details:&amp;nbsp;&lt;a href="http://www.c-sharpcorner.com/UploadFile/chinnasrihari/3180/" target="_blank"&gt;http://www.c-sharpcorner.com/UploadFile/chinnasrihari/3180/&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-5500721364650627784?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/5500721364650627784/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=5500721364650627784' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/5500721364650627784'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/5500721364650627784'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/aspnet-url-rewriting-with-httphandler.html' title='ASP.NET URL Rewriting with HttpHandler'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-5537939414652109842</id><published>2011-05-07T11:55:00.000-07:00</published><updated>2011-05-07T12:01:49.324-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC (Model View Controller)'/><title type='text'>Basic concept and fundamentals of ASP.NET MVC (Model View Controller) Architecture</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Tahoma, sans-serif; font-size: 13px; line-height: 19px;"&gt;This is basic concepts and fundamentals of ASP.NET Model View Controller (MVC) architecture workflow.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Tahoma, sans-serif; font-size: 13px; line-height: 19px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;MVC is stands for MODEL VIEW CONTROLLER. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner than the traditional ASP.NET web development. Web applications developed with ASP.NET MVC are even more SEO (Search Engine) friendly.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Microsoft .Net Framework 3.5 is minimum requirement to develop ASP.net MVC application.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 style="line-height: 14.4pt;"&gt;&lt;span style="color: #ff9900; font-family: Tahoma, sans-serif;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2 style="line-height: 14.4pt;"&gt;&lt;span style="color: windowtext; font-family: Tahoma, sans-serif;"&gt;MVC (Model View Controller) Interaction with Browser&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Like a normal web server interaction, MVC application also accepts requests and responds to the web browser in the same way.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: 12.0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Tahoma, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small; line-height: normal;"&gt;&lt;a href="http://2.bp.blogspot.com/-j16C9ZAZ-CA/TcWUtflVTyI/AAAAAAAAAMo/EDScE-8_cLQ/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="163" src="http://2.bp.blogspot.com/-j16C9ZAZ-CA/TcWUtflVTyI/AAAAAAAAAMo/EDScE-8_cLQ/s320/1.png" style="cursor: move;" width="320" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 style="line-height: 14.4pt;"&gt;&lt;span style="color: #ff9900; font-family: Tahoma, sans-serif;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Tahoma, sans-serif;"&gt;Inside MVC Architecture&lt;/span&gt;&lt;/h2&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;The entire ASP.NET MVC architecture is based on Microsoft .NET Framework 3.5 and in addition uses LINQ to SQL Server.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h4 style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;What is a Model?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h4&gt;&lt;ol start="1" type="1"&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l2 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;MVC&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;model&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;is basically a C# or VB.NET class&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l2 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;A&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;model&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;is accessible by both&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;controller&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;and&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;view&lt;/span&gt;&lt;/strong&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l2 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;A&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;model&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;can be used to pass data from&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;Controller&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;to&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;view&lt;/span&gt;&lt;/strong&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l2 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;A&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;view&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;can use model to display data in      page.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-tH2m55afhl8/TcWUv1oQwWI/AAAAAAAAAMs/R8bajekpULc/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="210" src="http://2.bp.blogspot.com/-tH2m55afhl8/TcWUv1oQwWI/AAAAAAAAAMs/R8bajekpULc/s320/2.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Tahoma, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;h4 style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;What is a View?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h4&gt;&lt;ol start="1" type="1"&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l4 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;View is an ASPX      page without having a code behind file&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l4 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;All page      specific HTML generation and formatting can be done inside view&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l4 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;One can use      Inline code (server tags ) to develop dynamic pages&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l4 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;A request to&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;view&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;(ASPX page) can be made only from      a controller’s action method&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;strong&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;What is a Controller?&lt;/span&gt;&lt;/strong&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;ol start="1" type="1"&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l0 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Controller&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;is basically a C# or VB.NET class which      inherits&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;system.mvc.controller&lt;/span&gt;&lt;/strong&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l0 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Controller&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;is a heart of the entire MVC      architecture&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l0 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Inside&lt;span class="apple-converted-space"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;Controller’s class&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;action methods can be      implemented which are responsible for responding to browser OR calling      views.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l0 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Controller&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;can access and use&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;model&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;class to pass data to&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;views&lt;/span&gt;&lt;/strong&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l0 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Controller&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;b&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;uses&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;ViewData&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;to pass any data to&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;view&lt;/span&gt;&lt;/strong&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Tahoma, sans-serif; font-size: 24px; font-weight: bold; line-height: 19px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Tahoma, sans-serif; font-size: 24px; font-weight: bold; line-height: 19px;"&gt;MVC File Structure &amp;amp; File Naming Standards&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;MVC uses a standard directory structure and file naming standards which are a very important part of MVC application development.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Inside the ROOT directory of the application, there must be 3 directories each for model, view and Controller.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Apart from 3 directories, there must have a&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;em&gt;&lt;b&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;Global.asax&lt;/span&gt;&lt;/b&gt;&lt;/em&gt;&lt;span class="apple-converted-space"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;file in root folder, and a&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;em&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;web.config&lt;/span&gt;&lt;/em&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;like a traditional ASP.NET application.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l3 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Root&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;b&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;[directory]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;ul type="circle"&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l3 level2 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 1.0in;"&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Controller&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;[directory]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;ul type="square"&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l3 level3 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 1.5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Controller CS        files&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l3 level2 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 1.0in;"&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Models&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;[directory]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;ul type="square"&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l3 level3 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 1.5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Model CS        files&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l3 level2 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 1.0in;"&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Views&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;b&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;[directory]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;ul type="square"&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l3 level3 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 1.5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;View CS files&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l3 level2 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 1.0in;"&gt;&lt;em&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Global.asax&lt;/span&gt;&lt;/em&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l3 level2 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 1.0in;"&gt;&lt;em&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Web.config&lt;/span&gt;&lt;/em&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;h2 style="line-height: 14.4pt;"&gt;&lt;span style="color: windowtext; font-family: Tahoma, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2 style="line-height: 14.4pt;"&gt;&lt;span style="color: windowtext; font-family: Tahoma, sans-serif;"&gt;ASP.NET MVC Execution Life Cycle&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Here is how MVC architecture executes the requests to browser and objects interactions with each other.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;A step by step process is explained below&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;[Refer to the figure as given below]&lt;/span&gt;&lt;/strong&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&amp;nbsp;&lt;a href="http://2.bp.blogspot.com/-TdnB2ImBrjI/TcWUxa4aYGI/AAAAAAAAAMw/T8KPGSysiCY/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="261" src="http://2.bp.blogspot.com/-TdnB2ImBrjI/TcWUxa4aYGI/AAAAAAAAAMw/T8KPGSysiCY/s320/3.png" style="cursor: move;" width="320" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Tahoma, sans-serif; font-size: 19px; font-weight: bold; line-height: 19px;"&gt;Browser Request (Step 1)&lt;/span&gt;&lt;br /&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Browser request happens with a specific URL. Let’s assume that the user enters URL like: [xyz.com]/home/index/&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style="line-height: 14.4pt;"&gt;&lt;span style="color: windowtext; font-family: Tahoma, sans-serif;"&gt;Job of Global.asax – MVC routing (Step 2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;The specified URL will first get parsed via&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="color: #990000; font-family: Tahoma, sans-serif; font-size: 11pt;"&gt;application_start()&lt;/span&gt;&lt;/code&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;method inside&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;em&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;Global.asax&lt;/span&gt;&lt;/em&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;file. From the requested URL, it will parse the&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;Controller, Action and ID.&lt;/span&gt;&lt;/strong&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;So for [xyz.com]/home/index/:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l1 level1 lfo5; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Controller =      home&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l1 level1 lfo5; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Action =      index()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black; line-height: 14.4pt; mso-list: l1 level1 lfo5; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"&gt;&lt;span style="font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;ID = empty — we      have not specified ID in [xyz.com]/home/index/, so it will consider as      empty string&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 style="line-height: 14.4pt;"&gt;&lt;span style="color: windowtext; font-family: Tahoma, sans-serif;"&gt;Controller and Action methods (Step 3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;MVC now finds the&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;home controller&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;class in controller directory. A controller class contains different action methods,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;There can be more than one action method, but MVC will only invoke the action method which has been parsed from the URL, its&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="color: #990000; font-family: Tahoma, sans-serif; font-size: 11pt;"&gt;index()&lt;/span&gt;&lt;/code&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: #990000; font-family: Tahoma, sans-serif; font-size: 11pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;in our case.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;So something like:&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="color: #990000; font-family: Tahoma, sans-serif; font-size: 11pt;"&gt;homeController.index()&lt;/span&gt;&lt;/code&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: #990000; font-family: Tahoma, sans-serif; font-size: 11pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;will happen inside MVC controller class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Invoking action method can return plain text string OR rendered HTML by using view.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style="line-height: 14.4pt;"&gt;&lt;span style="color: windowtext; font-family: Tahoma, sans-serif;"&gt;Call to View (Step 4)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style="line-height: 14.4pt;"&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;Invoking view will return&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="color: #990000; font-family: Tahoma, sans-serif; font-size: 11pt;"&gt;view()&lt;/span&gt;&lt;/code&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt;"&gt;. A call to view will access the particular ASPX page inside the view directory and generate the rendered HTML from the ASPX and will respond back to the browser.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt; line-height: 115%;"&gt;In our case, controller was&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;home&lt;/span&gt;&lt;/strong&gt;&lt;span class="apple-converted-space"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;and action was&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="color: #990000; font-family: Tahoma, sans-serif; font-size: 11pt; line-height: 115%;"&gt;index()&lt;/span&gt;&lt;/code&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt; line-height: 115%;"&gt;. So calling&lt;span class="apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="color: #990000; font-family: Tahoma, sans-serif; font-size: 11pt; line-height: 115%;"&gt;view()&lt;/span&gt;&lt;/code&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: #990000; font-family: Tahoma, sans-serif; font-size: 11pt; line-height: 115%;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black; font-family: Tahoma, sans-serif; font-size: 10pt; line-height: 115%;"&gt;will return a rendered HTML from the ASPX page located at&lt;em&gt;&lt;span style="font-family: Tahoma, sans-serif;"&gt;/views/home/index.aspx&lt;/span&gt;&lt;/em&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-5537939414652109842?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/5537939414652109842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=5537939414652109842' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/5537939414652109842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/5537939414652109842'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/05/basic-concept-and-fundamentals-of.html' title='Basic concept and fundamentals of ASP.NET MVC (Model View Controller) Architecture'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-j16C9ZAZ-CA/TcWUtflVTyI/AAAAAAAAAMo/EDScE-8_cLQ/s72-c/1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-6777900939693312074</id><published>2011-04-08T02:07:00.000-07:00</published><updated>2011-05-07T12:10:48.265-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC (Model View Controller)'/><title type='text'>MVC Architecture Model In ASP.NET</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: Arial, Helvetica, sans-serif; font-size: 13px;"&gt;When developing ASP.NET applications the need of reducing code duplication increases along with their complexity. This is because testing and performing changes become very difficult tasks when having many different sources of code with the same functionality.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: Arial, Helvetica, sans-serif; font-size: 13px;"&gt;Model View Controller architecture (or pattern) allows us to separate different parts of our applications into tiers to fulfill this need.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;h2 style="color: #3366ff; font-family: Arial, Helvetica, sans-serif; font-size: 16px;"&gt;MVC Overview&lt;/h2&gt;Model View Controller architecture aims to separate an application into three parts:&lt;br /&gt;&lt;b&gt;Model:&lt;/b&gt;&amp;nbsp;It is the business logic of an application. From an object oriented perspective it would consist of a set of classes that implement the critical functionality of an application from a business point of view.&lt;br /&gt;&lt;b&gt;View:&lt;/b&gt;&amp;nbsp;It can consist of every type of interface given to the user. In ASP.NET the view is the set of web pages presented by a web application.&lt;br /&gt;&lt;b&gt;Controller:&lt;/b&gt;&amp;nbsp;This part of the architecture is the most difficult to explain, hence the most difficult to implement in many platforms. The controller is the object that allows the manipulation of the view. Usually many applications implement Model-Controller tiers that contain the business logic along with the necessary code to manipulate a user interface. In an ASP.NET application the controller is implicitly represented by the code-behind or the server side code that generates the HTML presented to the user.&lt;br /&gt;&lt;h2 style="color: #3366ff; font-family: Arial, Helvetica, sans-serif; font-size: 16px;"&gt;Implementing MVC in ASP.NET&lt;/h2&gt;A basic diagram that would help us understand perfectly the specific parts that implement the Model View Controller architecture in an ASP.NET application is presented below:&lt;br /&gt;&lt;div align="center"&gt;&lt;img alt="MVC implementation in ASP.NET" src="http://www.beansoftware.com/ASP.NET-Tutorials/Images/MVC-Model-View-Controller.jpg" /&gt;&lt;/div&gt;&lt;h2 style="color: #3366ff; font-family: Arial, Helvetica, sans-serif; font-size: 16px;"&gt;MVC Model Implementation&lt;/h2&gt;When implementing the business logic of an application it is a must to use a Class Library project in order to generate a .dll file that will encapsulate all the functionality. This is critical as we as professional developers would not like to jeopardize the source code of a software product by placing the actual .cs files as a reference in a web application.&lt;br /&gt;This type of project can be easily created in Visual Studio 2005 under the Visual C# or Visual Basic tabs:&lt;br /&gt;&lt;div align="center"&gt;&lt;img alt="Creating a Class Library Project" src="http://www.beansoftware.com/ASP.NET-Tutorials/Images/MVC-Class-Library.jpg" /&gt;&lt;/div&gt;As a tutorial example we will develop a simple calculator under a new namespace we will call "Math".&lt;br /&gt;Once the project is created we will add a class called Calculator:&lt;br /&gt;&lt;div align="center"&gt;&lt;img alt="Adding Calculator class" src="http://www.beansoftware.com/ASP.NET-Tutorials/Images/MVC-Solution.jpg" /&gt;&lt;/div&gt;As the code is very simple and a sample is provided in this tutorial we will not get into much detail as far as how it is developed. The only important thing we need to mention is the way errors have to be handled in this class. Take a look at the following code:&lt;br /&gt;&lt;span&gt;1.&lt;span style="color: blue;"&gt;&amp;nbsp;protected&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;float&lt;/span&gt;&amp;nbsp;Divide(&lt;span style="color: blue;"&gt;float&lt;/span&gt;&amp;nbsp;fNumber1,&amp;nbsp;&lt;span style="color: blue;"&gt;float&lt;/span&gt;&amp;nbsp;fNumber2)&lt;/span&gt;&lt;br /&gt;&lt;span&gt;2. {&lt;/span&gt;&lt;br /&gt;&lt;span&gt;3.&amp;nbsp;&lt;span style="color: blue;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;if&lt;/span&gt;&amp;nbsp;(fNumber2 == 0)&lt;/span&gt;&lt;br /&gt;&lt;span&gt;4.&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt;5.&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;throw&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Exception&lt;/span&gt;(&amp;nbsp;&lt;span style="color: #a31515;"&gt;"Second number cannot be equal to zero."&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span&gt;6.&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;7.&lt;span style="color: blue;"&gt;&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;return&lt;/span&gt;&amp;nbsp;(fNumber1 / fNumber2);&lt;/span&gt;&lt;br /&gt;&lt;span&gt;8. }&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;br /&gt;When implementing the Divide function we need to ensure that the user would not be able to set the "fNumber2" parameter (line 1) to zero as a division between zero does not exist. The validation statement in lines 3-6 takes care of this case but the important fact we need to notice is that this class will NEVER use specific methods to present errors like message boxes or writing into labels. Errors captured in the model part of the architecture ALWAYS have to be presented in the form of exceptions (line 5). This will allow us to use this object in several types of applications like ASP.NET applications, Windows applications, Web services, etc.&lt;br /&gt;Once we have finished coding our Calculator class the project has to be built in order to get the .dll file we will use in our Web application.&lt;br /&gt;&lt;h2 style="color: #3366ff; font-family: Arial, Helvetica, sans-serif; font-size: 16px;"&gt;MVC View-Controller Implementation&lt;/h2&gt;The View and the Controller objects will be implemented by using a common ASP.NET Website. Once we have created our project we need to add the reference to the .dll file we created before.&lt;br /&gt;The option to do this can be found in the context menu when right-clicking the project in the solution explorer:&lt;br /&gt;&lt;div align="center"&gt;&lt;img alt="Adding the a reference" src="http://www.beansoftware.com/ASP.NET-Tutorials/Images/MVC-Add-Reference.jpg" /&gt;&lt;/div&gt;We can find the file in the path "\bin\Release" (or "\bin\Debug" depending on how you build your class library) inside our main folder containing the math class library project:&lt;br /&gt;&lt;div align="center"&gt;&lt;img alt="Adding Math.dll reference" src="http://www.beansoftware.com/ASP.NET-Tutorials/Images/MVC-Math.jpg" /&gt;&lt;/div&gt;Once we have referenced our library we will create a simple web page that will allow us to choose between the four basic arithmetic operations and type two different numbers to operate.&lt;br /&gt;The web page will look like this:&lt;br /&gt;&lt;div align="center"&gt;&lt;img alt="Calculator Web page" src="http://www.beansoftware.com/ASP.NET-Tutorials/Images/MVC-Form.jpg" /&gt;&lt;/div&gt;In the code behind we need to reference the Math namespace in order to use our Calculator class. The following statement will do that:&lt;br /&gt;using Math;&lt;br /&gt;As the code for this application is also simple we will only explain the method called when the "Operate!" button is clicked:&lt;br /&gt;&lt;span&gt;1.&lt;span style="color: blue;"&gt;&amp;nbsp;protected&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;btnOperate_Click(&lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;nbsp;sender,&amp;nbsp;&lt;span style="color: #2b91af;"&gt;EventArgs&lt;/span&gt;&amp;nbsp;e)&lt;/span&gt;&lt;br /&gt;&lt;span&gt;2. {&lt;/span&gt;&lt;br /&gt;&lt;span&gt;3.&lt;span style="color: blue;"&gt;&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;if&lt;/span&gt;&amp;nbsp;(pbValidateNumbers())&lt;/span&gt;&lt;br /&gt;&lt;span&gt;4.&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt;5.&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;Calculator&lt;/span&gt;&amp;nbsp;cOperator =&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Calculator&lt;/span&gt;();&lt;/span&gt;&lt;br /&gt;&lt;span&gt;6.&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;try&lt;/span&gt;&lt;br /&gt;&lt;span&gt;7.&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt;8.&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;txtResult.Text = cOperator.Operate(&lt;span style="color: blue;"&gt;float&lt;/span&gt;.Parse(txtNumber1.Text.Trim()),&lt;span style="color: blue;"&gt;float&lt;/span&gt;.Parse(txtNumber2.Text.Trim()),&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Convert&lt;/span&gt;.ToInt16(rblOperations.SelectedValue)).ToString();&lt;/span&gt;&lt;br /&gt;&lt;span&gt;9. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;lbError.Text =&amp;nbsp;&lt;span style="color: #a31515;"&gt;""&lt;/span&gt;;&lt;br /&gt;&lt;span&gt;10.&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;11.&amp;nbsp;&lt;span style="color: blue;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;catch&lt;/span&gt;&amp;nbsp;(&lt;span style="color: #2b91af;"&gt;Exception&lt;/span&gt;&amp;nbsp;ex)&lt;/span&gt;&lt;br /&gt;&lt;span&gt;12.&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt;13.&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;txtResult.Text =&amp;nbsp;&lt;span style="color: #a31515;"&gt;""&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;14.&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;lbError.Text = ex.Message;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;15.&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;16.&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;17.}&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;br /&gt;In line 3 we call the bool function "pbValidateNumbers" that will return true if the numbers typed in both textboxes are valid. These types of validations have to be performed by the controller object as they allow the interface to work properly and have nothing to do with the business logic.&lt;br /&gt;In line 5 we create an instance of our Calculator class so we can perform the arithmetic operation. We call the method "Operate" (line 8) and return the value in another textbox. An important thing to mention is that we have to use a try-catch statement (lines 6-15) to handle any exception that could be thrown by our method "Operate" as every error caught in our Calculator class is handled by throwing a "digested" exception that is readable to the user.&lt;br /&gt;In the code above we can appreciate how well encapsulated the business logic is, hence it can be reused in several applications without having to code it again.&lt;br /&gt;&lt;h2 style="color: #3366ff; font-family: Arial, Helvetica, sans-serif; font-size: 16px;"&gt;Advantages of using MVC in ASP.NET&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;See full details:&amp;nbsp;&lt;a href="http://www.beansoftware.com/ASP.NET-Tutorials/MVC-Architecture-Model.aspx" target="_blank"&gt;http://www.beansoftware.com/ASP.NET-Tutorials/MVC-Architecture-Model.aspx&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-6777900939693312074?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/6777900939693312074/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=6777900939693312074' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/6777900939693312074'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/6777900939693312074'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/04/mvc-architecture-model-in-aspnet.html' title='MVC Architecture Model In ASP.NET'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-3804455352082386186</id><published>2011-03-25T06:12:00.000-07:00</published><updated>2011-03-25T06:13:05.774-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>LINQ Query Syntax Tutorial</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: verdana; font-size: x-small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Probably the most exciting new feature of LINQ is the ability to write in line SQL style queries, known as query expressions (using query syntax). &amp;nbsp;This tutorial introduces the basic concepts, and comes complete with source code and demo applications.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;What is LINQ Query Syntax?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;LINQ query syntax is a set of query keywords&amp;nbsp;built into the .NET framework (3.5 and higher) that allow the developer to write SQL style commands in line straight in the code editor, without the use of quotes.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Introduction&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The .NET framework 3.5 introduces us to the following query keywords;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;from / in -&amp;nbsp;Specifies the data source&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;where -&amp;nbsp;Conditional boolean expression (e.g. i == 0)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;orderby (ascending/descending) -&amp;nbsp;Sorts the results into ascending or descending order&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;select -&amp;nbsp;Adds the result to the return type&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;group / by -&amp;nbsp;Groups the results based on a given key&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;There are more keywords that provide additional functionality, but they are outside the scope&amp;nbsp;of this tutorial.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Writing your first query&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The quickest easiest way to learn how to write query expressions is to go right ahead and just do it.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This tutorial assumes that we have the following Generic List, called "Characters", present in our project;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;i&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;i&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;readonly&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;List&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Character&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;gt; Characters =&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;List&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Character&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="color: green;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;//Format: Character Name, Gender, Number of episodes&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span style="color: green;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Character&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;(&lt;/span&gt;&lt;span style="color: #a31515;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;"Charlie"&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Gender&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;.Male, 162),&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Character&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;(&lt;/span&gt;&lt;span style="color: #a31515;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;"Alan"&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Gender&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;.Male, 162),&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Character&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;(&lt;/span&gt;&lt;span style="color: #a31515;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;"Berta"&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Gender&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;.Female, 117),&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Character&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;(&lt;/span&gt;&lt;span style="color: #a31515;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;"Jake"&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Gender&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;.Male, 162),&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Character&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;(&lt;/span&gt;&lt;span style="color: #a31515;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;"Evelyn"&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Gender&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;.Female, 78),&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Character&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;(&lt;/span&gt;&lt;span style="color: #a31515;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;"Judith"&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #2b91af;"&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;Gender&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;.Female, 69)&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;};&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;b&gt;&lt;u&gt;Note&lt;/u&gt;&lt;/b&gt;: The Character class above is just a trivial class containing a string, enum and integer. &amp;nbsp;You could do this same example with any data types.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Here is our first example;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #2b91af; font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #2b91af; font-family: Verdana, sans-serif;"&gt;IEnumerable&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;Character&lt;/span&gt;&amp;gt; results =&amp;nbsp;&lt;span style="color: blue;"&gt;from&lt;/span&gt;&amp;nbsp;character&amp;nbsp;&lt;span style="color: blue;"&gt;in&lt;/span&gt;&amp;nbsp;Characters&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;where&lt;/span&gt;&amp;nbsp;character.Episodes &amp;gt; 120&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;select&lt;/span&gt;&amp;nbsp;character;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span"&gt;&lt;/span&gt;Ok, lets just take a closer look;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-style: normal;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;div&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;span style="color: blue;"&gt;from&lt;/span&gt;&amp;nbsp;character&amp;nbsp;&lt;span style="color: blue;"&gt;in&lt;/span&gt;&amp;nbsp;Characters&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span style="color: blue;"&gt;where&lt;/span&gt;&amp;nbsp;character.Episodes &amp;gt; 120&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span style="color: blue;"&gt;select&lt;/span&gt;&amp;nbsp;character;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;We have three things going on here;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Specify the data source (Characters) and a temporary variable for each element within the data source (in this case a Generic List)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Create a condition with a boolean result used to query the data source&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;If the condition is met, select the temporary variable and add it to our results collection (IEnumerable&lt;type&gt;)&lt;/type&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The above statement returns a list of all the "characters" whom have appeared in more than 120 episodes. &amp;nbsp;We can then use a foreach loop to iterate through the list of results and do whatever we need to do.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This is a good example of a basic LINQ query expression. &amp;nbsp;We can also do more interesting things like;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Make our conditions as complicated as we need;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;i&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;where&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;character.Episodes &amp;gt; 120 &amp;amp;&amp;amp; character.Episodes &amp;lt; 200&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Order our results list in Ascending or Descending keywords;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;i&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;from&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;character&amp;nbsp;&lt;span style="color: blue;"&gt;in&lt;/span&gt;&amp;nbsp;Characters&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;where&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;character.Episodes &amp;gt; 120&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;orderby&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;character.Name&amp;nbsp;&lt;span style="color: blue;"&gt;ascending&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;span style="color: blue;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;select&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;character;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="display: inline !important; line-height: normal; margin-bottom: 0pt;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;/i&gt;And even group the results;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;from&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;character&amp;nbsp;&lt;span style="color: blue;"&gt;in&lt;/span&gt;&amp;nbsp;Characters&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;where&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;character.Episodes &amp;gt; 0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;group&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;character&amp;nbsp;&lt;span style="color: blue;"&gt;by&lt;/span&gt;&amp;nbsp;character.Episodes;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The demo project/source code available at the top of the page shows these scenarios in action.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Mixing Query Syntax and Extension Methods&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The System.Linq namespace also gives us the ability to to use LINQ's built in extension methods on the results of our query expressions. &amp;nbsp;For example, instead of storing the results of the query in a variable and then calling the Count extension method and storing the result in another variable, we can just do it all right on a single line;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: blue; font-family: Verdana, sans-serif;"&gt;int&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;count = (&lt;span style="color: blue;"&gt;from&lt;/span&gt;&amp;nbsp;character&amp;nbsp;&lt;span style="color: blue;"&gt;in&lt;/span&gt;&amp;nbsp;Characters&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;where&lt;/span&gt;&amp;nbsp;character.Episodes &amp;gt; 120&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;select&lt;/span&gt;&amp;nbsp;character).Count();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;All we need to do to achieve this is wrap our expression in parenthesis.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;See full details:&amp;nbsp;&lt;a href="http://www.c-sharpcorner.com/UploadFile/jonpreecebsc/3853/" target="_blank"&gt;http://www.c-sharpcorner.com/UploadFile/jonpreecebsc/3853/&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-3804455352082386186?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/3804455352082386186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=3804455352082386186' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/3804455352082386186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/3804455352082386186'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/03/linq-query-syntax-tutorial.html' title='LINQ Query Syntax Tutorial'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-7480738611481649238</id><published>2011-02-23T12:49:00.000-08:00</published><updated>2011-02-23T12:58:49.133-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><title type='text'>Performance Tips of  WPF</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;WPF (Windows Presentation Foundation) provides a very easy way to develop rich user experiences. A drop shadow for example can added by inserting two simple lines of XML. But this simplicity can also mislead us to overuse them. This leads to performance issues. The following tips may help you to fix&amp;nbsp;or avoid&amp;nbsp;them.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;b&gt;1. Reduce the number of visuals&lt;/b&gt; by removing unneeded elements, combining layout panels and simplifying templates. This keeps the memory footprint small and improves the rendering performance.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt; &lt;br /&gt;&lt;b&gt;2. Lower the framerate of animations&lt;/b&gt; by setting Storyboard.DesiredFrameRate to lower the CPU load. The default is 60 frames/second&lt;br /&gt;&lt;br /&gt;&lt;b&gt;3. Load resources when needed.&lt;/b&gt; Even thow it's the most comfortable way to merge all resources on application level it can also cost performance by loading all resources at startup. A better approach is to load only often used resources and load the other on view level.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;4. Enable Container Recycling.&lt;/b&gt; Virtualization brings a lot of performance improvements, but the containers will be disposed and re created, this is the default. But you can gain more performance by recycle containers by setting VirtualizingStackPanel.VirtualizationMode="Recycling"&lt;br /&gt;&lt;br /&gt;&lt;b&gt;5. Disable Assembly localization if you don't need it.&lt;/b&gt; By using the [NeutralResourcesLanguageAttribute]. This prevents an expensive lookup for satelite assemblies&lt;br /&gt;&lt;br /&gt;&lt;b&gt;6. Dispatch expensive calls&lt;/b&gt; either within the UI thread with a lower DispatcherPriority by calling Dispatcher.BeginInvoke() or to a background thread by using a BackgroundWorker to keep the UI responsive.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;7. Use StreamGeometries&lt;/b&gt; instead of PathGeometries if possible to draw complex 2D geometries, because they are much more efficient and consume less memory.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;8. Prevent Software Rendering.&lt;/b&gt; The use of transparent windows by setting AllowsTransparency to true or using old BitmapEffects can cause WPF to render the UI in software on Windows XP, which is much slower.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;9. Fix binding errors&lt;/b&gt; because they consume a lot of time, trying to resolve the path error, including searching for attached properties. You can find them by looking for System.Windows.Data Error in the Visual Studio output log.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;10. Freeze Freezables&lt;/b&gt; by calling Freeze() in code or PresentationOptions:Freeze="true" in XAML. This reduces memory consumption and improves performance, because the system don't need to monitor for changes.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;11. Virtualize lists and views&lt;/b&gt; by using a VirtualizingStackPanel as ItemsPanel for lists. This only creates the visible elements at load time. All other elements are lazy created when they get visible. Be aware that grouping or CanContextScrol="True" prevents virtualization!&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7328185059134214054-7480738611481649238?l=blog.dotnettechy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.dotnettechy.com/feeds/7480738611481649238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7328185059134214054&amp;postID=7480738611481649238' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/7480738611481649238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7328185059134214054/posts/default/7480738611481649238'/><link rel='alternate' type='text/html' href='http://blog.dotnettechy.com/2011/02/performance-tips-of-wpf.html' title='Performance Tips of  WPF'/><author><name>Must</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7328185059134214054.post-3088077267156439093</id><published>2010-12-03T22:33:00.000-08:00</published><updated>2010-12-03T22:33:27.223-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Date; SQL Server'/><title type='text'>DATEADD (Transact-SQL)</title><content type='html'>&lt;div class="topicContainer" style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px; padding-bottom: 96px; padding-left: 13px; padding-right: 13px;"&gt;&lt;div class="topic" xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;div id="mainSection" style="padding-top: 5px;"&gt;&lt;div id="mainBody"&gt;&lt;div class="introduction"&gt;Returns a specified&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;with the specified&amp;nbsp;&lt;span class="parameter"&gt;number&lt;/span&gt;&amp;nbsp;interval (signed integer) added to a specified&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;of that&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;.&lt;br /&gt;For an overview of all Transact-SQL date and time data types and functions, see&amp;nbsp;&lt;span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms186724.aspx" style="color: #1364c4; text-decoration: none;"&gt;Date and Time Functions (Transact-SQL)&lt;/a&gt;&lt;/span&gt;. For information and examples that are common to date and time data types and functions, see&amp;nbsp;&lt;span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms180878.aspx" style="color: #1364c4; text-decoration: none;"&gt;Using Date and Time Data&lt;/a&gt;&lt;/span&gt;.&lt;br /&gt;&lt;img alt="Topic link icon" class="cl_IC128933" id="Topic_Link" src="http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gif" style="background-attachment: scroll; background-clip: initial; background-color: initial; background-image: url(http://i3.msdn.microsoft.com/Hash/5fc2d4d93504fe872c01323c3a37c3bb.png); background-origin: initial; background-position: -1841px -3px; background-repeat: no-repeat no-repeat; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; height: 16px; overflow-x: hidden; overflow-y: hidden; width: 16px;" title="Topic link icon" xmlns="" /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms177563.aspx" style="color: #1364c4; text-decoration: none;"&gt;Transact-SQL Syntax Conventions&lt;/a&gt;&lt;/div&gt;&lt;div class="LW_CollapsibleArea_Container" xmlns=""&gt;&lt;div class="LW_CollapsibleArea_TitleDiv" style="margin-bottom: 19px; margin-top: 19px;"&gt;&lt;span class="LW_CollapsibleArea_Title" style="color: #3f529c; float: left; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.538em; font-weight: bold;"&gt;Syntax&lt;/span&gt;&lt;div class="LW_CollapsibleArea_HrDiv" style="padding-top: 12px;"&gt;&lt;hr class="LW_CollapsibleArea_Hr" style="border-bottom-color: rgb(229, 229, 229); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: initial; border-top-style: none; border-top-width: initial; color: #e5e5e5; margin-left: 4px;" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href="" id="syntaxToggle" xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;/a&gt;&lt;div class="LW_CodeSnippetContainer" style="min-width: 260px;" xmlns=""&gt;&lt;a href="" name="CodeSpippet0"&gt;&lt;/a&gt;&lt;div class="LW_CodeSnippetContainerCodeCollection" style="border-bottom-color: rgb(229, 229, 229); border-bottom-style: solid; border-bottom-width: 3px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(229, 229, 229); border-right-style: solid; border-right-width: 1px; clear: both; margin-bottom: 12px; position: relative; top: -3px;"&gt;&lt;div class="LW_CodeSnippetToolBar" style="border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(229, 229, 229); border-right-style: solid; border-right-width: 3px; border-top-color: rgb(229, 229, 229); border-top-style: solid; border-top-width: 3px; height: auto; width: auto;"&gt;&lt;div class="LW_CodeSnippetToolBarText" style="background-color: white; float: right; height: 0px; padding-left: 4px; padding-right: 4px; position: relative; top: -10px; width: auto;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms186819.aspx" style="background-color: white; color: #1364c4; font-family: 'Segoe UI', Verdana, Arial; font-size: 10pt; margin-left: 5px; margin-right: 5px; padding-left: 4px; padding-right: 4px; text-decoration: none;" title="Copy to clipboard."&gt;Copy&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="LW_CodeSnippetContainerCode" id="CodeSnippetContainerCode0" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 21px; padding-right: 21px; width: auto;"&gt;&lt;div style="color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;pre style="font-family: Consolas, Courier, monospace; font-style: normal; font-weight: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all; word-wrap: break-word;"&gt;DATEADD (datepart , number , date )&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="LW_CollapsibleArea_Container" xmlns=""&gt;&lt;div class="LW_CollapsibleArea_TitleDiv" style="margin-bottom: 19px; margin-top: 19px;"&gt;&lt;span class="LW_CollapsibleArea_Title" style="color: #3f529c; float: left; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.538em; font-weight: bold;"&gt;Arguments&lt;/span&gt;&lt;div class="LW_CollapsibleArea_HrDiv" style="padding-top: 12px;"&gt;&lt;hr class="LW_CollapsibleArea_Hr" style="border-bottom-color: rgb(229, 229, 229); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: initial; border-top-style: none; border-top-width: initial; color: #e5e5e5; margin-left: 4px;" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href="" id="sectionToggle0" xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;/a&gt;&lt;br /&gt;&lt;dl class="authored" xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;dt&gt;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;Is the part of&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;to which an&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;integer&lt;/span&gt;&lt;/span&gt;&lt;span class="parameter"&gt;number&lt;/span&gt;&amp;nbsp;is added. The following table lists all valid&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;arguments. User-defined variable equivalents are not valid.&lt;div class="caption" style="clear: both !important; color: #3f529c; font-size: 1.007em; font-weight: bold; height: 20px !important;"&gt;&lt;/div&gt;&lt;div class="tableSection"&gt;&lt;table style="border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; width: 1001px;"&gt;&lt;tbody&gt;&lt;tr style="vertical-align: top;"&gt;&lt;th style="background-color: #e5e5e5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; color: black; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.077em; font-style: normal; font-weight: normal; height: 21px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px; text-align: left;"&gt;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&lt;/th&gt;&lt;th style="background-color: #e5e5e5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; color: black; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.077em; font-style: normal; font-weight: normal; height: 21px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px; text-align: left;"&gt;Abbreviations&lt;/th&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;year&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;yy&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;yyyy&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;quarter&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;qq&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;q&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;month&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;mm&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;m&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;dayofyear&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;dy&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;day&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;dd&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;d&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;week&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;wk&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;ww&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;weekday&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;dw&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;w&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;hour&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;hh&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;minute&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;mi&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;second&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;ss&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;millisecond&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;ms&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;microsecond&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;mcs&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;nanosecond&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td style="background-color: white; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px;"&gt;&lt;span&gt;&lt;span class="input"&gt;ns&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span class="parameter"&gt;number&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;Is an expression that can be resolved to an&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/ms187745.aspx" style="color: #1364c4; text-decoration: none;"&gt;int&lt;/a&gt;&amp;nbsp;that is added to a&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;of&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;. User-defined variables are valid.If you specify a value with a decimal fraction, the fraction is truncated and not rounded.&lt;/dd&gt;&lt;dt&gt;&lt;span class="parameter"&gt;date&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;Is an expression that can be resolved to a&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;time&lt;/span&gt;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;date&lt;/span&gt;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;smalldatetime&lt;/span&gt;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;datetime&lt;/span&gt;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;datetime2&lt;/span&gt;&lt;/span&gt;, or&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;datetimeoffset&lt;/span&gt;&lt;/span&gt;&amp;nbsp;value.&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;can be an expression, column expression, user-defined variable, or string literal. If the expression is a string literal, it must resolve to a&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;datetime&lt;/span&gt;&lt;/span&gt;. To avoid ambiguity, use four-digit years. For information about two-digit years, see&amp;nbsp;&lt;span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms189577.aspx" style="color: #1364c4; text-decoration: none;"&gt;two digit year cutoff Option&lt;/a&gt;&lt;/span&gt;.&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;div class="LW_CollapsibleArea_Container" xmlns=""&gt;&lt;div class="LW_CollapsibleArea_TitleDiv" style="margin-bottom: 19px; margin-top: 19px;"&gt;&lt;span class="LW_CollapsibleArea_Title" style="color: #3f529c; float: left; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.538em; font-weight: bold;"&gt;Return Types&lt;/span&gt;&lt;div class="LW_CollapsibleArea_HrDiv" style="padding-top: 12px;"&gt;&lt;hr class="LW_CollapsibleArea_Hr" style="border-bottom-color: rgb(229, 229, 229); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: initial; border-top-style: none; border-top-width: initial; color: #e5e5e5; margin-left: 4px;" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href="" id="sectionToggle1" xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;/a&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;The return data type is the data type of the&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;argument, except for string literals.&lt;/div&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;The return data type for a string literal is&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;datetime&lt;/span&gt;&lt;/span&gt;. An error will be raised if the string literal seconds scale is more than three positions (.nnn) or contains the time zone offset part.&lt;/div&gt;&lt;div class="alert" style="background-color: #fcfec5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 1px; margin-bottom: 10px;" xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;table style="border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 0px; border-collapse: collapse; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 0px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 0px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 0px; width: 1040px;"&gt;&lt;tbody&gt;&lt;tr style="vertical-align: top;"&gt;&lt;th style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; background-color: #fcfec5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: hidden; border-bottom-width: 0px; border-collapse: collapse; border-left-color: rgb(187, 187, 187); border-left-style: hidden; border-left-width: 0px; border-right-color: rgb(187, 187, 187); border-right-style: hidden; border-right-width: 0px; border-top-color: rgb(187, 187, 187); border-top-style: hidden; border-top-width: 0px; color: black; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.077em; font-style: normal; font-weight: bold; height: 21px; padding-bottom: 1px; padding-left: 11px; padding-right: 11px; padding-top: 10px; text-align: left;"&gt;&lt;img alt="Note" class="cl_IC101471" id="alert_note" src="http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gif" style="background-attachment: scroll; background-clip: initial; background-color: initial; background-image: url(http://i3.msdn.microsoft.com/Hash/5fc2d4d93504fe872c01323c3a37c3bb.png); background-origin: initial; background-position: -1903px -3px; background-repeat: no-repeat no-repeat; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; height: 14px; overflow-x: hidden; overflow-y: hidden; padding-right: 5px; width: 16px;" title="Note" xmlns="" /&gt;&amp;nbsp;&lt;strong&gt;Note&lt;/strong&gt;&lt;/th&gt;&lt;/tr&gt;&lt;tr style="vertical-align: top;"&gt;&lt;td style="background-color: #fcfec5; border-bottom-color: rgb(187, 187, 187); border-bottom-style: solid; border-bottom-width: 0px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 0px; border-right-color: rgb(187, 187, 187); border-right-style: solid; border-right-width: 0px; border-top-color: rgb(187, 187, 187); border-top-style: solid; border-top-width: 0px; line-height: 18px; margin-bottom: 1px; margin-left: 1px; margin-right: 1px; margin-top: 1px; padding-bottom: 10px; padding-left: 11px; padding-right: 11px; padding-top: 1px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;If string literals are not explicitly cast for the&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;parameter then locals that use a day-month-year (dmy) date format may get incorrect results when DATEADD is used in conjunction with other date/time functions.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;h3 class="subHeading" style="color: #3f529c; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.077em; font-weight: bold;" xmlns="http://www.w3.org/1999/xhtml"&gt;Returning a datetime2 type&lt;/h3&gt;&lt;div class="subsection" xmlns="http://www.w3.org/1999/xhtml"&gt;DATEADD returns a&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;datetime2&lt;/span&gt;&lt;/span&gt;&amp;nbsp;type when the&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;parameter is a&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;datetime2&lt;/span&gt;&lt;/span&gt;&amp;nbsp;type. When using string literals for the&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;parameter, then you must explicitly cast them to a&lt;span&gt;&lt;span class="input"&gt;datetime2&lt;/span&gt;&lt;/span&gt;&amp;nbsp;type for DATEADD to return a&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;datetime2&lt;/span&gt;&lt;/span&gt;&amp;nbsp;type.&lt;/div&gt;&lt;/div&gt;&lt;div class="LW_CollapsibleArea_Container" xmlns=""&gt;&lt;div class="LW_CollapsibleArea_TitleDiv" style="margin-bottom: 19px; margin-top: 19px;"&gt;&lt;span class="LW_CollapsibleArea_Title" style="color: #3f529c; float: left; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.538em; font-weight: bold;"&gt;datepart Argument&lt;/span&gt;&lt;div class="LW_CollapsibleArea_HrDiv" style="padding-top: 12px;"&gt;&lt;hr class="LW_CollapsibleArea_Hr" style="border-bottom-color: rgb(229, 229, 229); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: initial; border-top-style: none; border-top-width: initial; color: #e5e5e5; margin-left: 4px;" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href="" id="returnValueToggle" xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;/a&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;span&gt;&lt;span class="input"&gt;dayofyear&lt;/span&gt;&amp;nbsp;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;day&lt;/span&gt;&lt;/span&gt;, and&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;weekday&lt;/span&gt;&lt;/span&gt;&amp;nbsp;return the same value.&lt;/div&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;Each&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;and its abbreviations return the same value.&lt;/div&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;If&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;is&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;month&lt;/span&gt;&lt;/span&gt;&amp;nbsp;and the&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;month has more days than the return month and the&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;day does not exist in the return month, the last day of the return month is returned. For example, September has 30 days; therefore, the two following statements return 2006-09-30 00:00:00.000:&lt;/div&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;span class="code"&gt;SELECT DATEADD(month, 1, '2006-08-30')&lt;/span&gt;&lt;/div&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;span class="code"&gt;SELECT DATEADD(month, 1, '2006-08-31')&lt;/span&gt;&lt;/div&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;The&amp;nbsp;&lt;span class="parameter"&gt;number&lt;/span&gt;&amp;nbsp;argument cannot exceed the range of&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;int&lt;/span&gt;&lt;/span&gt;. In the following statements, the argument for&amp;nbsp;&lt;span class="parameter"&gt;number&lt;/span&gt;&amp;nbsp;exceeds the range of&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;int&lt;/span&gt;&lt;/span&gt;&amp;nbsp;by 1. The following error message is returned: "Arithmetic overflow error converting expression to data type int."&lt;/div&gt;&lt;div class="LW_CodeSnippetContainer" style="min-width: 260px;" xmlns=""&gt;&lt;a href="" name="CodeSpippet1"&gt;&lt;/a&gt;&lt;div class="LW_CodeSnippetContainerCodeCollection" style="border-bottom-color: rgb(229, 229, 229); border-bottom-style: solid; border-bottom-width: 3px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(229, 229, 229); border-right-style: solid; border-right-width: 1px; clear: both; margin-bottom: 12px; position: relative; top: -3px;"&gt;&lt;div class="LW_CodeSnippetToolBar" style="border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(229, 229, 229); border-right-style: solid; border-right-width: 3px; border-top-color: rgb(229, 229, 229); border-top-style: solid; border-top-width: 3px; height: auto; width: auto;"&gt;&lt;div class="LW_CodeSnippetToolBarText" style="background-color: white; float: right; height: 0px; padding-left: 4px; padding-right: 4px; position: relative; top: -10px; width: auto;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms186819.aspx" style="background-color: white; color: #1364c4; font-family: 'Segoe UI', Verdana, Arial; font-size: 10pt; margin-left: 5px; margin-right: 5px; padding-left: 4px; padding-right: 4px; text-decoration: none;" title="Copy to clipboard."&gt;Copy&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="LW_CodeSnippetContainerCode" id="CodeSnippetContainerCode1" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 21px; padding-right: 21px; width: auto;"&gt;&lt;div style="color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;pre style="font-family: Consolas, Courier, monospace; font-style: normal; font-weight: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all; word-wrap: break-word;"&gt;SELECT DATEADD(year,2147483648, '2006-07-31');&lt;br /&gt;SELECT DATEADD(year,-2147483649, '2006-07-31');&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;The&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;argument cannot be incremented to a value outside the range of its data type. In the following statements, the&amp;nbsp;&lt;span class="parameter"&gt;number&lt;/span&gt;&amp;nbsp;value that is added to the&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;value exceeds the range of the&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;data type. The following error message is returned: "Adding a value to a 'datetime' column caused overflow."&lt;/div&gt;&lt;div class="LW_CodeSnippetContainer" style="min-width: 260px;" xmlns=""&gt;&lt;a href="" name="CodeSpippet2"&gt;&lt;/a&gt;&lt;div class="LW_CodeSnippetContainerCodeCollection" style="border-bottom-color: rgb(229, 229, 229); border-bottom-style: solid; border-bottom-width: 3px; border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(229, 229, 229); border-right-style: solid; border-right-width: 1px; clear: both; margin-bottom: 12px; position: relative; top: -3px;"&gt;&lt;div class="LW_CodeSnippetToolBar" style="border-left-color: rgb(187, 187, 187); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(229, 229, 229); border-right-style: solid; border-right-width: 3px; border-top-color: rgb(229, 229, 229); border-top-style: solid; border-top-width: 3px; height: auto; width: auto;"&gt;&lt;div class="LW_CodeSnippetToolBarText" style="background-color: white; float: right; height: 0px; padding-left: 4px; padding-right: 4px; position: relative; top: -10px; width: auto;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms186819.aspx" style="background-color: white; color: #1364c4; font-family: 'Segoe UI', Verdana, Arial; font-size: 10pt; margin-left: 5px; margin-right: 5px; padding-left: 4px; padding-right: 4px; text-decoration: none;" title="Copy to clipboard."&gt;Copy&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="LW_CodeSnippetContainerCode" id="CodeSnippetContainerCode2" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-left: 21px; padding-right: 21px; width: auto;"&gt;&lt;div style="color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;pre style="font-family: Consolas, Courier, monospace; font-style: normal; font-weight: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all; word-wrap: break-word;"&gt;SELECT DATEADD(year,2147483647, '2006-07-31');&lt;br /&gt;SELECT DATEADD(year,-2147483647, '2006-07-31');&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;The seconds part of a&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/ms182418.aspx" style="color: #1364c4; text-decoration: none;"&gt;smalldatetime&lt;/a&gt;&amp;nbsp;value is always 00. If&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;is&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;smalldatetime&lt;/span&gt;&lt;/span&gt;, the following apply:&lt;/div&gt;&lt;ul style="list-style-type: disc; margin-left: 40px; padding-left: 0px;" xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;li style="list-style-image: url(http://i3.msdn.microsoft.com/Hash/fcc063e32e5c2395ba48efadd8423b60.gif);"&gt;If&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;is&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;second&lt;/span&gt;&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;span class="parameter"&gt;number&lt;/span&gt;&amp;nbsp;is between -30 and +29, no addition is performed.&lt;/li&gt;&lt;li style="list-style-image: url(http://i3.msdn.microsoft.com/Hash/fcc063e32e5c2395ba48efadd8423b60.gif);"&gt;If&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;is&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;second&lt;/span&gt;&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;span class="parameter"&gt;number&lt;/span&gt;&amp;nbsp;is less than-30 or more than +29, addition is performed beginning at one minute.&lt;/li&gt;&lt;li style="list-style-image: url(http://i3.msdn.microsoft.com/Hash/fcc063e32e5c2395ba48efadd8423b60.gif);"&gt;If&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;is&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;millisecond&lt;/span&gt;&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;span class="parameter"&gt;number&lt;/span&gt;&amp;nbsp;is between -30001 and +29998, no addition is performed.&lt;/li&gt;&lt;li style="list-style-image: url(http://i3.msdn.microsoft.com/Hash/fcc063e32e5c2395ba48efadd8423b60.gif);"&gt;If&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;is&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;millisecond&lt;/span&gt;&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;span class="parameter"&gt;number&lt;/span&gt;&amp;nbsp;is less than -30001 or more than +29998, addition is performed beginning at one minute.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="LW_CollapsibleArea_Container" xmlns=""&gt;&lt;div class="LW_CollapsibleArea_TitleDiv" style="margin-bottom: 19px; margin-top: 19px;"&gt;&lt;span class="LW_CollapsibleArea_Title" style="color: #3f529c; float: left; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.538em; font-weight: bold;"&gt;Remarks&lt;/span&gt;&lt;div class="LW_CollapsibleArea_HrDiv" style="padding-top: 12px;"&gt;&lt;hr class="LW_CollapsibleArea_Hr" style="border-bottom-color: rgb(229, 229, 229); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: initial; border-top-style: none; border-top-width: initial; color: #e5e5e5; margin-left: 4px;" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href="" id="languageReferenceRemarksToggle" xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;/a&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;DATEADD can be used in the SELECT &lt;list&gt;, WHERE, HAVING, GROUP BY and ORDER BY clauses.&lt;/list&gt;&lt;/div&gt;&lt;h3 class="subHeading" style="color: #3f529c; font-family: 'Segoe UI', Verdana, Arial; font-size: 1.077em; font-weight: bold;" xmlns="http://www.w3.org/1999/xhtml"&gt;Fractional Seconds Precision&lt;/h3&gt;&lt;div class="subsection" xmlns="http://www.w3.org/1999/xhtml"&gt;Addition for a&amp;nbsp;&lt;span class="parameter"&gt;datepart&lt;/span&gt;&amp;nbsp;of&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;microsecond&lt;/span&gt;&lt;/span&gt;&amp;nbsp;or&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;nanosecond&lt;/span&gt;&lt;/span&gt;&amp;nbsp;for&amp;nbsp;&lt;span class="parameter"&gt;date&lt;/span&gt;&amp;nbsp;data types&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;smalldatetime&lt;/span&gt;&lt;/span&gt;,&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;date&lt;/span&gt;&lt;/span&gt;, and&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;datetime&lt;/span&gt;&lt;/span&gt;&amp;nbsp;is not allowed.&lt;br /&gt;Milliseconds have a scale of 3 (.123). microseconds have a scale of 6 (.123456). nanoseconds have a scale of 9 (.123456789). The&amp;nbsp;&lt;span&gt;&lt;span class="input"&gt;time&lt;/span&gt;&lt;/span&gt;,&amp;nbsp;&lt;span
