<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-110778182955953940</atom:id><lastBuildDate>Thu, 24 Oct 2024 08:18:51 +0000</lastBuildDate><category>MVC3 razor view</category><category>asp.net razor view</category><category>razor view basics</category><category>razor view engine</category><category>&#39;like&#39; button in asp.net</category><category>ASP.NET</category><category>ASP.NET Performance</category><category>Alternative of cursor</category><category>Cookiess(Autodetect) and Googlebot</category><category>Create Index for all tables</category><category>Display Image in asp.net</category><category>Handle Errors in AJAX</category><category>Handling Errors with the UpdatePanel control</category><category>Optimize Webpage</category><category>SQL Server cursor alternates</category><category>SiteMapResolve</category><category>Thumbnailer HTTP Handler</category><category>Thumbnailer in asp.net</category><category>Track User Activity in ASP.NET</category><category>Treeview using jquery</category><category>Viewstate Compression</category><category>asp.net cookieless and googlebot</category><category>asp.net jquery treeview</category><category>asp.net master pages and facebook &#39;like&#39; button</category><category>auto detect cookie and google indexing</category><category>create all indexes in table</category><category>create script for non-clustered indexs</category><category>dynamic sitemap</category><category>dynamic sitemapnode</category><category>facebook &#39;like&#39; button asp.net master pages</category><category>facebook &#39;like&#39; button in asp.net</category><category>googlebot and cookieless sessions</category><category>jquery treeview</category><category>loop wihout cursor</category><category>tree in jquery</category><title>Viresh Shah&#39;s Blog</title><description>I like my new telephone, my computer works just fine, my calculator is perfect, but Lord, I miss my mind!</description><link>http://vireshvshah.blogspot.com/</link><managingEditor>noreply@blogger.com (Viresh Shah)</managingEditor><generator>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-8145963985285140401</guid><pubDate>Wed, 25 Apr 2012 03:31:00 +0000</pubDate><atom:updated>2012-04-25T09:37:06.763+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">asp.net razor view</category><category domain="http://www.blogger.com/atom/ns#">MVC3 razor view</category><category domain="http://www.blogger.com/atom/ns#">razor view basics</category><category domain="http://www.blogger.com/atom/ns#">razor view engine</category><title>Welcome ASP.NET Razor View - Part 2</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The previous part  introduces with an Asp.net Razor web site, which is built on top of  Razor view engine. This part will cover some basic Razor stuff which  would be kind of essentials to know, in order to develop an Asp.net  Razor web site based application.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Here we go&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;As  you might know already, unlike the Asp.net Web Forms, there is no  Server control or CodeBehind classes available in Razor web sites. All  you have is the cshtml files, which contains the plain old html markups  with simple Razor expressions @. In Razor, you stay closest to the basic  HTML, that gives you the power to customize the front-end functionality  to your heart&#39;s content. The good news is, even though you don&#39;t have  the powerful server controls here, you&#39;ve got powerful built-in Helpers  which lets you add complex user interface modules with functionality in  the cshtml pages. Razor is simple, and beautiful.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Following are some of the basic Razor things that you should know, in order to be able to start building a real application:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;The IsPost property&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Like  the IsPostBack property in Asp.net web forms, you can determine whether  the current Request is due to a form Post or Get request by checking  the IsPost property as follows:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj82-wttyHdPV9rXf0Z8u3dhJlwfzsGGBTp_MqpX0JimuY5yTdxQgmFCT7tCtc62OstAUMM417gJw2I-BLZx-dcG8xVQ8eMNQoH2Vq1c-72klthVPyh4bk5-mC7BmamYoUtte_IQE8gfRg/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj82-wttyHdPV9rXf0Z8u3dhJlwfzsGGBTp_MqpX0JimuY5yTdxQgmFCT7tCtc62OstAUMM417gJw2I-BLZx-dcG8xVQ8eMNQoH2Vq1c-72klthVPyh4bk5-mC7BmamYoUtte_IQE8gfRg/s320/1.png&quot; width=&quot;320&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Mixture of HTML and Razor &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;In Razor, @ is just a replacement
of the server side expression &amp;lt;%=%&amp;gt; and &amp;lt;%...%&amp;gt;
which are using in aspx web forms. Using the @ symbol doesn&#39;t require you to
end the expression with something, which greatly simplifies the mixture of HTML
markups and server side expressions and improves readability a lot.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Have a look at the following
codes:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhp788bKzZDNyC4EXLzNlJ-KKI8hDRqarigqsmrLbYcHch9hjmPDYSwy6d8fGuE72LDIZFTjcbzx4GraddwrQAcu4GLlHq13oVtYzdQX5c65y4P7IsE1HZKCu9RnlSOFZV59n6NUeucbZY/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;104&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhp788bKzZDNyC4EXLzNlJ-KKI8hDRqarigqsmrLbYcHch9hjmPDYSwy6d8fGuE72LDIZFTjcbzx4GraddwrQAcu4GLlHq13oVtYzdQX5c65y4P7IsE1HZKCu9RnlSOFZV59n6NUeucbZY/s320/2.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The basic rule is, you start any
server side expression with @, and, you don&#39;t need to end it. All of the other
programmatic syntax should be there as they should be, like, if you open the
curly brace &quot;{&quot;, you need to close it &quot;}&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4TbF74wH5E03tYX9oRW2sZdfzDLZzGpzkuD8pUsXsDMDsCRBznAkE9AWn_JqWU9O_CpXpKEFEC-vkBuAn1SLyENqAA7mCKXCEOykj8fDaJrZa7gkaqATiSBeucNGjMxCqiKsdiADUl_Y/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;66&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4TbF74wH5E03tYX9oRW2sZdfzDLZzGpzkuD8pUsXsDMDsCRBznAkE9AWn_JqWU9O_CpXpKEFEC-vkBuAn1SLyENqAA7mCKXCEOykj8fDaJrZa7gkaqATiSBeucNGjMxCqiKsdiADUl_Y/s320/3.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;

&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;The @Href method&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;For resolving correct relative
paths for resources in HTML, the @Href method is your good friend. The WebPage object
(The current object of the page, equivalent to the Page object in WebForms) has
this handy method, which could be used as follows to resolve correct relative
paths:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGnfu2jxOTcYxASF-i7uDKrK8i5TUty6dNfcEJxRtnN41WvKlE0ElFgcrLBkAqg3u6nICGmKeRr3HQcKPudhGi1tSR2PaKBd10BfDsiHVN_Da7GkGCkhYJfFLnoePYhP-HMIg5b6-ujdM/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;31&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGnfu2jxOTcYxASF-i7uDKrK8i5TUty6dNfcEJxRtnN41WvKlE0ElFgcrLBkAqg3u6nICGmKeRr3HQcKPudhGi1tSR2PaKBd10BfDsiHVN_Da7GkGCkhYJfFLnoePYhP-HMIg5b6-ujdM/s320/4.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Including another page using
@RenderPage()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The layout pages contain a
@RenderBody()&amp;nbsp; method, which is replaced by the content of a child page at
run-time. Using the layout page thus gives a way to have consistent look of the
entire site.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Much like the @RenderBody(),
there is another way you can include the output of an another page in an
existing page. The&lt;b&gt; @RenderPage(PageName) &lt;/b&gt;method allows such facility.
For example, a layout page could have a @RenderPage(PageName) to include the
output of another page in it. It works much like adding a User Control in an
aspx page.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;_SiteLayout.cshtml&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy5TcWl_sTJfVF6DvV47jThcZHJv4D-ZNwQOJnZ43zHY-Yp4D9rWu1WHEmzxVqwtXLznTjcyjuMUrTF9O1kTUq_Bix_aw-NE7ewP-mnYQB3QVJVa2a6IjRmgUjSwZM1c2Kh8J85ruwgx0/s1600/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;111&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy5TcWl_sTJfVF6DvV47jThcZHJv4D-ZNwQOJnZ43zHY-Yp4D9rWu1WHEmzxVqwtXLznTjcyjuMUrTF9O1kTUq_Bix_aw-NE7ewP-mnYQB3QVJVa2a6IjRmgUjSwZM1c2Kh8J85ruwgx0/s320/5.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;

&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;

&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Passing data to Layout page&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Passing data from the content
page to Layout page is a very basic need. Pages in Razor has a PageData
property which is used for this purpose. The following example shows passing
Page title from the content page to the Layout page:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-4lj8uZLhuIRxP9y9SUhh2PPPlNLhsfPeMXrECMZlPMXYsWYHSLxlyEK8zQSRJpLf_s22dcQMYu7Av-GRFT14doqZVsOQQnn5swRDr7kftvEe6TrvnDHGJvKAbvMHwjqmf-99PuJWjc/s1600/6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-4lj8uZLhuIRxP9y9SUhh2PPPlNLhsfPeMXrECMZlPMXYsWYHSLxlyEK8zQSRJpLf_s22dcQMYu7Av-GRFT14doqZVsOQQnn5swRDr7kftvEe6TrvnDHGJvKAbvMHwjqmf-99PuJWjc/s320/6.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Helpers&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;A helper is a component that lets
you accomplish a task using a single line of code. ASP.NET includes many
built-in helpers which are ready to be used in cshtml files, such as the
following, which displays data in Grid layout using the built-in WebGrid
helper:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPxW1XJn4qdn1m0plfQGbHwOwLDjJBCgFrmzlt1MH4hAJ4d_lEsfLpTuDQpSQNgSmFf1vfe4knkWE1AFQO60-rVGcf7i8kRQ0ztzngQ8kqCy33qlSuLZ6l9RVx9F7MGpnOC231Shnwi0I/s1600/7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;170&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPxW1XJn4qdn1m0plfQGbHwOwLDjJBCgFrmzlt1MH4hAJ4d_lEsfLpTuDQpSQNgSmFf1vfe4knkWE1AFQO60-rVGcf7i8kRQ0ztzngQ8kqCy33qlSuLZ6l9RVx9F7MGpnOC231Shnwi0I/s320/7.png&quot; width=&quot;320&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;There are many built-in helpers
which you could use to achieve several necessary functions and features. Some
are as follows:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The &lt;b&gt;WebCache &lt;/b&gt;helper : Lets
you using Caching in cshtml pages as follows:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ3NHr3-yoReuqwRMU00aGn9xyADvb8AsiXX-9GKoRTgm5AlMgpK2RQ35ihyphenhyphenaSOdANt-OR9I5eRUvwt95-faKa7XKMRoirhjYxRVkwHazKE3iA21vLx_dqSikQ5fkGaKSNGAEzoYoDFUQ/s1600/8.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;104&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ3NHr3-yoReuqwRMU00aGn9xyADvb8AsiXX-9GKoRTgm5AlMgpK2RQ35ihyphenhyphenaSOdANt-OR9I5eRUvwt95-faKa7XKMRoirhjYxRVkwHazKE3iA21vLx_dqSikQ5fkGaKSNGAEzoYoDFUQ/s320/8.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The &lt;b&gt;FileUpload &lt;/b&gt;helper :
Lets you upload single or multiple files&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3huodjXp0SaNMEgWcU_o4_APicR4IUAOQXU4GrEAhPEVmVnvLXL61uDO_sQex5f1_s57psoH15yVKy5bXT52QKb1hEDwIOUp9rJ8QFuBkBlRxfP1jMl6RxN41yFvhlL1GsVVd3hRqvjI/s1600/9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;173&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3huodjXp0SaNMEgWcU_o4_APicR4IUAOQXU4GrEAhPEVmVnvLXL61uDO_sQex5f1_s57psoH15yVKy5bXT52QKb1hEDwIOUp9rJ8QFuBkBlRxfP1jMl6RxN41yFvhlL1GsVVd3hRqvjI/s320/9.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The &lt;b&gt;Video &lt;/b&gt;helper : Lets
you include a Video in the page&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8qc9QekUFajmOe7H6iPpb00ynwXPE8qNq7SA9HhyphenhyphenXCBMsyrOyPNLtvYStB-Joh8_-SVTcSl10fmKjQPI5377wyp1dENjrsIxTcB2OCgPyY8bpuof9eUORmSU4LuBTSDBL9lRhY49CB_Y/s1600/SiteLayout.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8qc9QekUFajmOe7H6iPpb00ynwXPE8qNq7SA9HhyphenhyphenXCBMsyrOyPNLtvYStB-Joh8_-SVTcSl10fmKjQPI5377wyp1dENjrsIxTcB2OCgPyY8bpuof9eUORmSU4LuBTSDBL9lRhY49CB_Y/s320/SiteLayout.png&quot; width=&quot;305&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZckCEte1cyUY6zdn-s2vPgjUtxbVco4z68LZkr6Mcg7lEeuxe-Y0hN7__mwSTJ7JAogcHo0FTfw-yeTuAjR5NY9gR-q0YNzrm6dD3kwyOCEpw0OBGYcmS1L1o0z6IJlIcN0gqHAYc4IU/s1600/10.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;210&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZckCEte1cyUY6zdn-s2vPgjUtxbVco4z68LZkr6Mcg7lEeuxe-Y0hN7__mwSTJ7JAogcHo0FTfw-yeTuAjR5NY9gR-q0YNzrm6dD3kwyOCEpw0OBGYcmS1L1o0z6IJlIcN0gqHAYc4IU/s320/10.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The &lt;b&gt;WebMail &lt;/b&gt;helper : Lets
you send emails&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYMoRIQeBcEUrbomw97YRW002tpEZ-jixrOYrmRla7SJUe9LqxL96GkpIYN3dOb0FboqOhoeqQVU7my27AXJC9scTP47PUHli5naCxEhleG-nxi8acRYiU_GorXfuzVPKYrKD_d9biNOc/s1600/11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;223&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYMoRIQeBcEUrbomw97YRW002tpEZ-jixrOYrmRla7SJUe9LqxL96GkpIYN3dOb0FboqOhoeqQVU7my27AXJC9scTP47PUHli5naCxEhleG-nxi8acRYiU_GorXfuzVPKYrKD_d9biNOc/s320/11.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The &lt;b&gt;Bing &lt;/b&gt;helper : Lets you
add a search functionality with Bing search engine&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNMZLG6XGGlFH-KrkRcEqZIWgGJo14mmE9Z34hd8laTqxScXmS6aT-y00fQveCzp3W5j3-16PEjb8HXCKq9kTRmovxGbrcfCZ62Gkx4QIdEA6BlskUkx6GGVdutx5Tl_gM7CH3Zx5kJr8/s1600/12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNMZLG6XGGlFH-KrkRcEqZIWgGJo14mmE9Z34hd8laTqxScXmS6aT-y00fQveCzp3W5j3-16PEjb8HXCKq9kTRmovxGbrcfCZ62Gkx4QIdEA6BlskUkx6GGVdutx5Tl_gM7CH3Zx5kJr8/s320/12.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The &lt;b&gt;LinkShare &lt;/b&gt;helper.&lt;br /&gt;
The &lt;b&gt;Twitter &lt;/b&gt;helper.&lt;br /&gt;
The &lt;b&gt;Facebook &lt;/b&gt;helper.&lt;b&gt;&lt;br /&gt;
&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;These let you add social network functionality in cshtml pages&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt; &lt;/b&gt;The &lt;b&gt;WebSecurity &lt;/b&gt;helper.&lt;br /&gt;
The &lt;b&gt;SimpleMembership &lt;/b&gt;helper.&lt;br /&gt;
The &lt;b&gt;ReCaptcha &lt;/b&gt;helper.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;These let you implement user registration and login functionality with Membership&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Custom helpers&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;You
 also may want to create and use custom helpers in your application and 
use that helper across the pages for a consistent look and functions. 
Here is how you can do this:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;1. Add the App_Code folder in your web site&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;2. Create a new .cshtml file inside App_Code folder&amp;nbsp; and name it Helpers.cshtml.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;3. Replace the existing content with the following and save the file:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6eNg71-g1LddK6nEwBCyEMFc_9UhV69NagspuFKC7LyZ7kPOrAN94xHX4ehbPXeiEbk9nvF7D76qWb00XiQyQ53TFqPxWR4yDI-g25simQriitgz-BUcFkgeyS31jwc1pOKXC8T5TfTQ/s1600/13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;84&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6eNg71-g1LddK6nEwBCyEMFc_9UhV69NagspuFKC7LyZ7kPOrAN94xHX4ehbPXeiEbk9nvF7D76qWb00XiQyQ53TFqPxWR4yDI-g25simQriitgz-BUcFkgeyS31jwc1pOKXC8T5TfTQ/s320/13.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Once created, you can use the helper as follows:&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWAugcmbRqvfHNZh37ZeaeEPepnHprMVpXxpCRA8_KoTv8m5Qv9pggfYzZK_U__J6lpcOm2y4X2qeeLPMPZ3pl9zd1dixImy36jAbt1mFXfYdC4Bf2VPjuji-hnEPkZKI7ZrWdPMZQ17I/s1600/14.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;105&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWAugcmbRqvfHNZh37ZeaeEPepnHprMVpXxpCRA8_KoTv8m5Qv9pggfYzZK_U__J6lpcOm2y4X2qeeLPMPZ3pl9zd1dixImy36jAbt1mFXfYdC4Bf2VPjuji-hnEPkZKI7ZrWdPMZQ17I/s320/14.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Further study&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Enjoyed Razor? Does it seem interesting? See &lt;a href=&quot;http://www.asp.net/webmatrix/tutorials/1-getting-started-with-webmatrix-and-asp-net-web-pages&quot;&gt;http://www.asp.net/webmatrix/tutorials/1-getting-started-with-webmatrix-and-asp-net-web-pages&lt;/a&gt; for more detailed on Asp.net Razor and keep exploring, Razor is fun.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;div&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number10 index9 alt1&quot;&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;div&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number15 index14 alt2&quot;&gt;
&lt;div&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number10 index9 alt1&quot;&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;div&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number18 index17 alt1&quot;&gt;
&lt;div&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number20 index19 alt1&quot;&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number18 index17 alt1&quot;&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt; &lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;csharp plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;csharp plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;csharp plain&quot;&gt; &lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;</description><link>http://vireshvshah.blogspot.com/2012/04/welcome-aspnet-razor-view-part-2.html</link><author>noreply@blogger.com (Viresh Shah)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj82-wttyHdPV9rXf0Z8u3dhJlwfzsGGBTp_MqpX0JimuY5yTdxQgmFCT7tCtc62OstAUMM417gJw2I-BLZx-dcG8xVQ8eMNQoH2Vq1c-72klthVPyh4bk5-mC7BmamYoUtte_IQE8gfRg/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-7279057901018234849</guid><pubDate>Wed, 25 Apr 2012 03:16:00 +0000</pubDate><atom:updated>2012-04-25T08:54:19.178+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">asp.net razor view</category><category domain="http://www.blogger.com/atom/ns#">MVC3 razor view</category><category domain="http://www.blogger.com/atom/ns#">razor view basics</category><category domain="http://www.blogger.com/atom/ns#">razor view engine</category><title>Welcome ASP.NET Razor View - Part 1</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Asp.net
 MVC3 introduces a new View Engine &quot;Razor&quot;, which greatly simplifies the
 creation of view components and improves productivity. Once you have 
installed MVC3 from &lt;a href=&quot;http://www.asp.net/mvc/mvc3&quot;&gt;http://www.asp.net/mvc/mvc3&lt;/a&gt;,
 when you create an Asp.net MVC3 application using Visual Studio 2010, 
you are going to see a prompt like the following where you need to 
specify the View Engine (Either Aspx or Razor):&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqPnUPms8wHE6YucKUOZDRxT_sBtYhKb1rcAV7vPlY9u015Jv0R8DltbPZF2EVRVpIAZ_IluIn-jHjR7jGnve2TYExZnQ4zbgimNiADjM_v9EpbqRYLvfCaoVsI35Yp8Z-U4YtzWre7Ug/s1600/Default.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxLQDX0NV93yKA0U062-c9vNbJtQ0vMX4VOVEgeG8MwELEiNwIXBuSzzRP1KMuLSaG2O7vKx9AdVjrpz013HM7xWJAfuGxfSYxnqL9BQQdeEJcqxKvR53AzAmdmeeUwL_7s-RbpH4KR8Y/s1600/Razor.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;296&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxLQDX0NV93yKA0U062-c9vNbJtQ0vMX4VOVEgeG8MwELEiNwIXBuSzzRP1KMuLSaG2O7vKx9AdVjrpz013HM7xWJAfuGxfSYxnqL9BQQdeEJcqxKvR53AzAmdmeeUwL_7s-RbpH4KR8Y/s320/Razor.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Figure : Specify View Enginge while creating an Asp.net MVC3 application&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Specifying
 &quot;Razor&quot; as the view engine results in creating an MVC application based
 on Razor view engine where the file extensions end up with .cshtml.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Interesting thing is, once you install Asp.net MVC3, you get a new template in Visual Studio to create an &lt;b&gt;Asp.net web site&lt;/b&gt;
 based on Razor view engine. Go to File-&amp;gt;New-&amp;gt;Web Site-&amp;gt;Asp.net
 Web Site(Razor) to add a Razor based Asp.net web site in Visual Studio:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidyIZb5pnWURsuob4UuM_jayZZDFFHzS05-oUGmzrdWYbpT7Yvaw7F4Kqsjt3JHg1Yy4v4mWl42n1ue_ZBt4kQRS49djNOlw2b8yv8dJSrqQHYqFTg6zpiQyVJ-cvVWq5ScH0FzCmVKZ4/s1600/RazorWebSite.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;94&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidyIZb5pnWURsuob4UuM_jayZZDFFHzS05-oUGmzrdWYbpT7Yvaw7F4Kqsjt3JHg1Yy4v4mWl42n1ue_ZBt4kQRS49djNOlw2b8yv8dJSrqQHYqFTg6zpiQyVJ-cvVWq5ScH0FzCmVKZ4/s320/RazorWebSite.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;b&gt;Figure :&lt;/b&gt; Adding an Asp.net Razor web site in Visual Studio&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Doing so would result in adding the following Web Site in Visual Studio, which is based on Razor view engine:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKiEK42AC-zUeU5MDMqddg-pgypDkijY7uj36FeSmB7B2JYcYbwsiZKf9WlM8PKs0YDf58AfZgu48kjbS3CO7Y_bgOHO05DqKahq6qYDKknvUpz8AY1kt1HymRBwfsQFZDDWyUsjOxp4c/s1600/RazorSolutionExplorer.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKiEK42AC-zUeU5MDMqddg-pgypDkijY7uj36FeSmB7B2JYcYbwsiZKf9WlM8PKs0YDf58AfZgu48kjbS3CO7Y_bgOHO05DqKahq6qYDKknvUpz8AY1kt1HymRBwfsQFZDDWyUsjOxp4c/s1600/RazorSolutionExplorer.png&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;b&gt;Figure :&lt;/b&gt; Asp.net Razor web site in Solution explorer&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Run the application using Visual Studio and you are likely to see the following output:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEib6OA2YPk2rMftsAKUXx7_x326O5ggmeupvU0rDycr2KyCgLFpby8GbhJsHxJmHI5bUKzo5iSAppYoprGGE5nIX_BN7HkJoBQcQ25mBxE7aAgFyTL9Kyh_lQyXBzyweGQAEeM5STt2mPE/s1600/RazorWebsiteOutput.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;165&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEib6OA2YPk2rMftsAKUXx7_x326O5ggmeupvU0rDycr2KyCgLFpby8GbhJsHxJmHI5bUKzo5iSAppYoprGGE5nIX_BN7HkJoBQcQ25mBxE7aAgFyTL9Kyh_lQyXBzyweGQAEeM5STt2mPE/s320/RazorWebsiteOutput.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Figure :&lt;/b&gt; Home page of Asp.net Razor web site&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Hm..seems good. Lets try to understand how this works!&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Default.cshtml&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;First
 of all, there is no aspx in Razor, and, no server control, ascx or 
CodeBehind. All you see is some plain cshtml files all over the web 
site.&lt;br /&gt;&lt;br /&gt;Open the Default.cshtml in Visual Studio
 (Which results in the above page output in browser) and you will see it
 contains the following markup:&lt;/span&gt;

&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqPnUPms8wHE6YucKUOZDRxT_sBtYhKb1rcAV7vPlY9u015Jv0R8DltbPZF2EVRVpIAZ_IluIn-jHjR7jGnve2TYExZnQ4zbgimNiADjM_v9EpbqRYLvfCaoVsI35Yp8Z-U4YtzWre7Ug/s1600/Default.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;56&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqPnUPms8wHE6YucKUOZDRxT_sBtYhKb1rcAV7vPlY9u015Jv0R8DltbPZF2EVRVpIAZ_IluIn-jHjR7jGnve2TYExZnQ4zbgimNiADjM_v9EpbqRYLvfCaoVsI35Yp8Z-U4YtzWre7Ug/s320/Default.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp; &lt;b&gt;Figure :&lt;/b&gt; Default.cshtml Markup&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;As
 you can see, it contains some plain old basic HTML and some C# scripts 
written in some new syntax. Yes, you got it right. Razor introduces a 
new simple way of writing scripts in HTML, which basically could be 
thought of as a simplified version of writing scripts which we were used
 to write in Aspx markup.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Conventionally, we used to write scripts or expressions in aspx as follows:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter  xml&quot; id=&quot;highlighter_150821&quot;&gt;
&lt;div class=&quot;toolbar&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;margin-left: 0px; margin-right: 0px; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&amp;lt;% &lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;xml plain&quot;&gt;var date = DateTime.Now;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;%&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;Current date is : &amp;lt;%=date %&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;This expression becomes the following in Razor syntax:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter  xml&quot; id=&quot;highlighter_468753&quot;&gt;
&lt;div class=&quot;toolbar&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;margin-left: 0px; margin-right: 0px; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;@{&amp;nbsp; &lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;xml plain&quot;&gt;var date = DateTime.Now;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;Current date is : @date&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;As
 a result, the markups in Razor view components (cshtml files) becomes a
 lot cleaner, saves a lot of key strokes for you and lets not forget 
this syntax is fully supported by Visual Studio intellisence. So, you 
are getting the best of both worlds.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Understanding _SiteLayout.cshtml&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Notice
 the markup of Default.cshtml and you will see it contains a very 
minimal amount of codes. Yet it results in a good amount of output in 
the browser. How is that possible?&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Well,
 the answer is _SiteLayout.cshtml. It acts like what the MasterPage does
 in a Web Form application and it is used in a Razor web site to define a
 common layout across a group of pages (cshtml files).&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;In
 Razor, if you start a cshtml file name with an underscore (_), user 
cannot browse the file using URL request (It is prohibited internally). 
The layout files are files which are to be used as an internal purpose 
(To define the common layout of the pages) and hence, a layout file name
 should always start with an underscore (_), like the default layout 
file _SiteLayout.cshtml.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Open the _SiteLayout.cshtml and you will see the following markups:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8qc9QekUFajmOe7H6iPpb00ynwXPE8qNq7SA9HhyphenhyphenXCBMsyrOyPNLtvYStB-Joh8_-SVTcSl10fmKjQPI5377wyp1dENjrsIxTcB2OCgPyY8bpuof9eUORmSU4LuBTSDBL9lRhY49CB_Y/s1600/SiteLayout.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8qc9QekUFajmOe7H6iPpb00ynwXPE8qNq7SA9HhyphenhyphenXCBMsyrOyPNLtvYStB-Joh8_-SVTcSl10fmKjQPI5377wyp1dENjrsIxTcB2OCgPyY8bpuof9eUORmSU4LuBTSDBL9lRhY49CB_Y/s320/SiteLayout.png&quot; width=&quot;305&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Figure :&lt;/b&gt; _SiteLayout.cshtml makrup&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Notice, its just plain old basic HTML stuff along with some Razor expressions which start with @. Most importantly, notice the &lt;b&gt;@RenderBody()&lt;/b&gt; method call in Red box. At run time, the &lt;b&gt;@RenderBody()&lt;/b&gt; method call is replaced by the HTML markups defined in the child page (The page which includes this layout page).&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;So, when the Default.cshtml is browsed, the &lt;b&gt;@RenderBody()&lt;/b&gt; method call is replaced by the HTML defined in Default.cshtml, which is nothing but the following simple HTML:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter  xml&quot; id=&quot;highlighter_502673&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;margin-left: 0px; margin-right: 0px; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;xml keyword&quot;&gt;p&lt;/code&gt;&lt;code class=&quot;xml plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;xml plain&quot;&gt;ASP.NET Web Pages make it easy to build powerful .NET based applications for the web.&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;&lt;code class=&quot;xml keyword&quot;&gt;p&lt;/code&gt;&lt;code class=&quot;xml plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Note
 that, there is no restriction of name with the layout pages except the 
fact that, it should always start with an underscore(_). Name it as you 
like and everything should be alright as long as you include the layout 
page correctly in children pages as follows:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;toolbar&quot; style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: Arial,Helvetica,sans-serif; margin-left: 0px; margin-right: 0px; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;@{&amp;nbsp; &lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;xml plain&quot;&gt;Layout = &quot;~/_MyLayoutPage.cshtml&quot;;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;xml plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Understanding _AppStart.cshtml&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;If
 you need to run some initialization functionality when the application 
starts, _AppStart.cshtml is the place to do so. Unlike the layout pages,
 it has a standard name and you cannot rename it other than 
_AppStart.cshtml.&lt;br /&gt;&lt;br /&gt;Open the _AppStart.cshtml and you would see the following markup:&lt;/span&gt;

&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNqYuw3_aJP2lB-FcsGQAW52mp5XjCdErgylyD76YC-LlKiI2jG9550ug46JlX0WFmhwhkJ2Lg71vtUDjflgpC1qjoVzMHCRJfUxRRNy2QAvDxBtK3PlmbeOKYYN9S_7e4Bgo1myvVGa4/s1600/_AppStart.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;57&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNqYuw3_aJP2lB-FcsGQAW52mp5XjCdErgylyD76YC-LlKiI2jG9550ug46JlX0WFmhwhkJ2Lg71vtUDjflgpC1qjoVzMHCRJfUxRRNy2QAvDxBtK3PlmbeOKYYN9S_7e4Bgo1myvVGa4/s320/_AppStart.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Figure :&lt;/b&gt; _AppStart.cshtml markup&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Basically, it contains some codes to initialize the database when the application runs.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Others &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Expand
 the Accounts folder and you will see several other cshtml files 
implemented for User Login, Registration and other user account oriented
 functionality. All of these utilizes Razor syntax and use the built in 
helpers in Razor for rendering various UI elements or built in classes 
for implementing several functionality.&lt;br /&gt;&lt;br /&gt;Like a conventional Asp.net web site, a 
Razor web site also can have Asp.net standard folders like the App_Data 
for holding database and other data sources, or, App_Codes for holding 
cs files. Similarly, the Razor web site can hold a reference to other 
class libraries to be able to invoke methods on those libraries to 
achieve desired functionality. Most importantly, it contains many rich 
built in &quot;Helpers&quot; which help rendering some common UI output and 
functionality (Like, Adding a Twitter feed, or, Social network 
bookmarks) which you would simply love to have!&lt;/span&gt;

&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;The next post is going to cover some of the detailed stuff of Razor and I hope you would find it helpful.&lt;/span&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;</description><link>http://vireshvshah.blogspot.com/2012/04/welcome-aspnet-razor-view-part-1.html</link><author>noreply@blogger.com (Viresh Shah)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxLQDX0NV93yKA0U062-c9vNbJtQ0vMX4VOVEgeG8MwELEiNwIXBuSzzRP1KMuLSaG2O7vKx9AdVjrpz013HM7xWJAfuGxfSYxnqL9BQQdeEJcqxKvR53AzAmdmeeUwL_7s-RbpH4KR8Y/s72-c/Razor.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-7855502360651743310</guid><pubDate>Wed, 12 Oct 2011 12:38:00 +0000</pubDate><atom:updated>2011-10-12T18:54:12.166+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">&#39;like&#39; button in asp.net</category><category domain="http://www.blogger.com/atom/ns#">asp.net master pages and facebook &#39;like&#39; button</category><category domain="http://www.blogger.com/atom/ns#">facebook &#39;like&#39; button asp.net master pages</category><category domain="http://www.blogger.com/atom/ns#">facebook &#39;like&#39; button in asp.net</category><title>Using facebook &#39;like&#39; button on asp.net master page</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Hi Everyone,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;First of all use Facebook like button generator from following link:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;https://developers.facebook.com/docs/reference/plugins/like/&quot; target=&quot;_blank&quot;&gt;Facebook Like Button Generator&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Copy and paste the generated iframe code into your master page.  If you leave it as is it will &#39;like&#39; your website site, not specific pages.&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;To &#39;like&#39; the individual pages you can take the generated code and look for a section like this:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;src=&quot;http://www.facebook.com/plugins/like.php?href=mysite.com&amp;amp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
now change above to :&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
src=&quot;http://www.facebook.com/plugins/like.php?href=&amp;lt;%=Request.Url.ToString() %&amp;gt;&amp;amp;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
Hurray!! your like button should be working for each page of your website.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
Happy Programming!!!&lt;/div&gt;
&lt;/div&gt;</description><link>http://vireshvshah.blogspot.com/2011/10/using-facebook-like-button-on-aspnet.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-7775944723512022173</guid><pubDate>Wed, 16 Jun 2010 09:10:00 +0000</pubDate><atom:updated>2010-06-16T14:40:49.879+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">asp.net cookieless and googlebot</category><category domain="http://www.blogger.com/atom/ns#">auto detect cookie and google indexing</category><category domain="http://www.blogger.com/atom/ns#">Cookiess(Autodetect) and Googlebot</category><category domain="http://www.blogger.com/atom/ns#">googlebot and cookieless sessions</category><title>Cookieless Session and Google Indexing (Googlebot)</title><description>Hi,&lt;br /&gt;
&lt;br /&gt;
Today I&#39;m discussing one of the challenging problem that I come across during my 5+ years of career. &lt;br /&gt;
&lt;br /&gt;
All of you must be developing website and these websites are automatically indexed by Google crawler named Googlebot. I was working on one of an e-commerce website which is developed in ASP.NET 3.5. It was previously developed in PHP and all of their pages were already crawled. After releasing 1st version we came to know that Google is not crawling our new pages. Though SEO is very vast area and genuinely I never involed in this process because we had an SEO experts in past who look after for this. But ththis time case was different and we didn&#39;t have any SEO expert. So I need to jump into it to findout what&#39;s wrong with the website and why Google is not able to crawl a new website pages.&lt;br /&gt;
&lt;br /&gt;
So googleing for some time we just came to know my website was using forms authentication for user authentication purpose. If you remember web.config has one parameter named &lt;b&gt;cookieless&lt;/b&gt; which we need to set either to AutoDetect or UseCookies to allow or disallow cookieless sessions. I had previously it was set to AutoDetect hence was appending session ids in the URL if u connect through cookieless browsers. Now when Googlebot tries to connect to website for crawling it was identified as Cookieless browser by ASP.NET engine and hence session id was appending in URL itself and 302 response was sent. That&#39;s was the issue because of Google was not able to index the new pages.&lt;br /&gt;
&lt;br /&gt;
Possible Solutions:&lt;br /&gt;
&lt;br /&gt;
1. The easiest solution to the problem is to stop using ASP.NET&#39;s AutoDetect session mode. &lt;br /&gt;
&lt;br /&gt;
2. If you need to use that feature though, you simply can configure ASP.NET to recognize Google&#39;s spider as supporting cookies. This article shows how. (http://www.kowitz.net/archive/2006/12/11/asp.net-2.0-mozilla-browser-detection-hole.aspx)&lt;br /&gt;
&lt;br /&gt;
3. You can implement automatic support for URL-based sessions yourself. This takes some time to implement, and the benefits may not be worth the implementation cost. It works like this:&lt;br /&gt;
- you use cloaking to generate session IDs if the visitor is not a web spider&lt;br /&gt;
- start generating session IDs only when the session is really needed for tracking (for example, after the visitor adds items to his or her shopping cart). This way you don&#39;t feed your users with URL-based session IDs unless you really need to.&lt;br /&gt;
&lt;br /&gt;
Happy Programming!!!&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
&lt;br /&gt;
http://www.seoegghead.com/blog/seo/aspnet-20-setting-dangerous-for-google-indexing-p217.html&lt;br /&gt;
http://www.kowitz.net/archive/2006/12/11/asp.net-2.0-mozilla-browser-detection-hole</description><link>http://vireshvshah.blogspot.com/2010/06/cookieless-session-and-google-indexing.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-4281758016533173276</guid><pubDate>Tue, 12 Jan 2010 10:49:00 +0000</pubDate><atom:updated>2010-01-12T16:20:30.232+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">asp.net jquery treeview</category><category domain="http://www.blogger.com/atom/ns#">jquery treeview</category><category domain="http://www.blogger.com/atom/ns#">tree in jquery</category><category domain="http://www.blogger.com/atom/ns#">Treeview using jquery</category><title>JQuery based TreeView</title><description>&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Hello All,&lt;/span&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Please follow the link for Jquery based tree&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.jstree.com/&quot;&gt;http://www.jstree.com/&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;Features at a glance:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/font&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Various data sources - HTML, JSON, XML &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Supports AJAX loading &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Drag &amp;amp; drop support &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Highly configurable &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Theme support + included themes &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Numerous callbacks to attach to &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Optional keyboard navigation &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Maintain the same tree in many languages &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Inline editing &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Open/close optional animation &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Define node types and fine tune them &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Configurable multitree drag &amp;amp; drop &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Optional multiple select &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Search function &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Supports plugins &amp;amp; datastores &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Optional state saving using cookies&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;Currently supported browsers are:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Internet Explorer 6+ &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Mozilla Firefox 2+ &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Safari 3+ &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Opera 9+ &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Google Chrome&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&amp;nbsp;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Happy Programming!!!&lt;/span&gt;&lt;br /&gt;
</description><link>http://vireshvshah.blogspot.com/2010/01/jquery-based-treeview.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-1526947446885941885</guid><pubDate>Tue, 12 Jan 2010 10:43:00 +0000</pubDate><atom:updated>2010-01-12T16:16:25.573+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Alternative of cursor</category><category domain="http://www.blogger.com/atom/ns#">loop wihout cursor</category><category domain="http://www.blogger.com/atom/ns#">SQL Server cursor alternates</category><title>Alternative of Cursor in SQL</title><description>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Hello Friends, &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;We know that how cursors are useful in SQL server and we know its drawback even as it consume lots of resource like RAM, Disk space, network bandwidth etc. Don’t think too much here is answer of your question of Alternative of Cursor in SQL. Please go through link below written by Mr. Vinodkumar.&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://extremeexperts.com/SQL/Articles/IterateTSQLResult.aspx&quot;&gt;http://extremeexperts.com/SQL/Articles/IterateTSQLResult.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Happy Coding!!!&lt;/span&gt;</description><link>http://vireshvshah.blogspot.com/2010/01/alternative-of-cursor-in-sql.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-7650094303426434584</guid><pubDate>Tue, 12 Jan 2010 10:33:00 +0000</pubDate><atom:updated>2010-01-12T16:14:34.931+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">create all indexes in table</category><category domain="http://www.blogger.com/atom/ns#">Create Index for all tables</category><category domain="http://www.blogger.com/atom/ns#">create script for non-clustered indexs</category><title>Script to generate Create Index Scripts for all indexes in table</title><description>&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;In most of the cases we design the database first and then we create the indexes. We had a need to provide scripts for all indexes in the tables. Following is the script to generate scripts for all non clustered indexes.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: 85%;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;-- Get all existing indexes, but NOT the primary keys&lt;br /&gt;
DECLARE cIX CURSOR FOR&lt;br /&gt;
SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID&lt;br /&gt;
FROM Sys.Indexes SI&lt;br /&gt;
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC ON SI.Name = TC.CONSTRAINT_NAME AND OBJECT_NAME(SI.Object_ID) = TC.TABLE_NAME&lt;br /&gt;
WHERE TC.CONSTRAINT_NAME IS NULL&lt;br /&gt;
AND OBJECTPROPERTY(SI.Object_ID, &#39;IsUserTable&#39;) = 1&lt;br /&gt;
ORDER BY OBJECT_NAME(SI.Object_ID), SI.Index_ID&lt;br /&gt;
&lt;br /&gt;
DECLARE @IxTable SYSNAME&lt;br /&gt;
DECLARE @IxTableID INT&lt;br /&gt;
DECLARE @IxName SYSNAME&lt;br /&gt;
DECLARE @IxID INT&lt;br /&gt;
&lt;br /&gt;
-- Loop through all indexes&lt;br /&gt;
OPEN cIX&lt;br /&gt;
FETCH NEXT FROM cIX INTO @IxTable, @IxTableID, @IxName, @IxID&lt;br /&gt;
WHILE (@@FETCH_STATUS = 0)&lt;br /&gt;
BEGIN&lt;br /&gt;
DECLARE @IXSQL NVARCHAR(4000) SET @IXSQL = &#39;&#39;&lt;br /&gt;
SET @IXSQL = &#39;CREATE &#39;&lt;br /&gt;
&lt;br /&gt;
-- Check if the index is unique&lt;br /&gt;
IF (INDEXPROPERTY(@IxTableID, @IxName, &#39;IsUnique&#39;) = 1)&lt;br /&gt;
SET @IXSQL = @IXSQL + &#39;UNIQUE &#39;&lt;br /&gt;
-- Check if the index is clustered&lt;br /&gt;
IF (INDEXPROPERTY(@IxTableID, @IxName, &#39;IsClustered&#39;) = 1)&lt;br /&gt;
SET @IXSQL = @IXSQL + &#39;CLUSTERED &#39;&lt;br /&gt;
&lt;br /&gt;
SET @IXSQL = @IXSQL + &#39;INDEX &#39; + @IxName + &#39; ON &#39; + @IxTable + &#39;(&#39;&lt;br /&gt;
&lt;br /&gt;
-- Get all columns of the index&lt;br /&gt;
DECLARE cIxColumn CURSOR FOR&lt;br /&gt;
SELECT SC.Name&lt;br /&gt;
FROM Sys.Index_Columns IC&lt;br /&gt;
JOIN Sys.Columns SC ON IC.Object_ID = SC.Object_ID AND IC.Column_ID = SC.Column_ID&lt;br /&gt;
WHERE IC.Object_ID = @IxTableID AND Index_ID = @IxID&lt;br /&gt;
ORDER BY IC.Index_Column_ID&lt;br /&gt;
&lt;br /&gt;
DECLARE @IxColumn SYSNAME&lt;br /&gt;
DECLARE @IxFirstColumn BIT SET @IxFirstColumn = 1&lt;br /&gt;
&lt;br /&gt;
-- Loop throug all columns of the index and append them to the CREATE statement&lt;br /&gt;
OPEN cIxColumn&lt;br /&gt;
FETCH NEXT FROM cIxColumn INTO @IxColumn&lt;br /&gt;
WHILE (@@FETCH_STATUS = 0)&lt;br /&gt;
BEGIN&lt;br /&gt;
IF (@IxFirstColumn = 1)&lt;br /&gt;
SET @IxFirstColumn = 0&lt;br /&gt;
ELSE&lt;br /&gt;
SET @IXSQL = @IXSQL + &#39;, &#39;&lt;br /&gt;
&lt;br /&gt;
SET @IXSQL = @IXSQL + @IxColumn&lt;br /&gt;
&lt;br /&gt;
FETCH NEXT FROM cIxColumn INTO @IxColumn&lt;br /&gt;
END&lt;br /&gt;
CLOSE cIxColumn&lt;br /&gt;
DEALLOCATE cIxColumn&lt;br /&gt;
&lt;br /&gt;
SET @IXSQL = @IXSQL + &#39;)&#39;&lt;br /&gt;
-- Print out the CREATE statement for the index&lt;br /&gt;
PRINT @IXSQL&lt;br /&gt;
&lt;br /&gt;
FETCH NEXT FROM cIX INTO @IxTable, @IxTableID, @IxName, @IxID&lt;br /&gt;
END&lt;br /&gt;
&lt;br /&gt;
CLOSE cIX&lt;br /&gt;
DEALLOCATE cIX&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
Happy Programming!!!&lt;br /&gt;
Cheers&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;</description><link>http://vireshvshah.blogspot.com/2010/01/script-to-generate-create-index-scripts.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-8040640094171982733</guid><pubDate>Thu, 24 Sep 2009 13:04:00 +0000</pubDate><atom:updated>2009-09-24T18:42:56.954+05:30</atom:updated><title>Set active tab on failed validation with ajax tabcontainer</title><description>Ajax Tab Container is one of the coolest control in ASP.NET but it has one problem when you&#39;re using mulitple validation controls on different tabs and on click of your submit button you need to set focus on the tab on which validation failed. Following javascript is useful to achive this:&lt;br /&gt;&lt;br /&gt;function RunValidationsAndSetActiveTab()&lt;br /&gt;{&lt;br /&gt;if (typeof (Page_Validators) == &quot;undefined&quot;) return;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;var noOfValidators = Page_Validators.length;&lt;br /&gt;for (var validatorIndex = 0; validatorIndex &lt; noOfValidators; validatorIndex++)&lt;br /&gt;{&lt;br /&gt;var validator = Page_Validators[validatorIndex];&lt;br /&gt;if(validator.validationGroup == &#39;CategoryGroup&#39;)&lt;br /&gt;{&lt;br /&gt;ValidatorValidate(validator);&lt;br /&gt;if (!validator.isvalid)&lt;br /&gt;{&lt;br /&gt;var tabPanel = validator.parentNode.control;&lt;br /&gt;if(typeof (tabPanel) != &quot;undefined&quot;)&lt;br /&gt;{&lt;br /&gt;var tabContainer = tabPanel.get_owner();&lt;br /&gt;tabContainer.set_activeTabIndex(tabPanel.get_tabIndex());&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;catch (Error)&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Please notice that we&#39;re using parentNode instead of parentElment because firefox doesn&#39;t recognize parentElement.&lt;br /&gt;&lt;br /&gt;In the button that is used to submit all the tabs at once where each tab has set of validations you can call the above method on click of button on client side such as:&lt;br /&gt;&lt;br /&gt;OnClientClick=&quot;RunValidationsAndSetActiveTab()&quot;&lt;br /&gt;&lt;br /&gt;Happy Programming!!!</description><link>http://vireshvshah.blogspot.com/2009/09/set-active-tab-on-validation-with-ajax.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-8735955501449774541</guid><pubDate>Wed, 15 Jul 2009 11:31:00 +0000</pubDate><atom:updated>2009-07-15T17:25:28.282+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">dynamic sitemap</category><category domain="http://www.blogger.com/atom/ns#">dynamic sitemapnode</category><category domain="http://www.blogger.com/atom/ns#">SiteMapResolve</category><title>Add nodes dynamically to the SiteMap For Your ASP.NET Site</title><description>&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;The Web.sitemap file stores only static URLs, so if you have a page like this:&lt;br /&gt;&lt;a href=&quot;http://yoursite.com/news.aspx?view=4&quot;&gt;http://yoursite.com/news.aspx?view=4&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Your sitemap breadcrumb will not reflect the fact that you are viewing a an actual news item. If you&#39;re like me, you also reflect the breadcrumb in the title of your page. So instead of seeing:&lt;br /&gt;Breadcrumb: Home &gt; News &gt; A headline! Title: A headline! : News : My Site&lt;br /&gt;You see:&lt;br /&gt;Home &gt; News News : My Site&lt;br /&gt;Read on for how to solve it.&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br /&gt;How do you fix it? I found a &lt;/span&gt;&lt;a href=&quot;http://zifiglio.blogspot.com/2007/01/sitemappath-control-and-dynamic-url.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;great post on how to nest the sitemap in a master-detail style&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; and then adjust the parent node&#39;s URL, but I wanted to actually add a new node because I was viewing and listing news on the same page.&lt;br /&gt;Here&#39;s how you do it:&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;span style=&quot;color:#666666;&quot;&gt;private string _mHeadline = string.Empty;&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;// Here you set the page title to whatever dynamic thing&lt;br /&gt;// you&#39;re loading.&lt;br /&gt;_mHeadline = &quot;A test&quot;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SiteMap.SiteMapResolve += SiteMapResolve;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void Page_Unload(object sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;// Remove this specific handler once the page is done.&lt;br /&gt;// Otherwise it will get called on other pages.&lt;br /&gt;SiteMap.SiteMapResolve -= SiteMapResolve;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected SiteMapNode SiteMapResolve(object sender, SiteMapResolveEventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;SiteMapNode cn = SiteMap.CurrentNode.Clone(true);&lt;br /&gt;SiteMapNode newNode = default(SiteMapNode);&lt;br /&gt;&lt;br /&gt;// &quot;viewnews&quot; can be changed to whatever you want. It&#39;s just a key.&lt;br /&gt;if (_mViewTitle != string.Empty) {&lt;br /&gt;newNode = new SiteMapNode(SiteMap.Provider, &quot;viewnews&quot;, Request.Url.PathAndQuery, _mHeadline);&lt;br /&gt;newNode.ParentNode = cn;&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;newNode = cn;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return newNode;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;So I left out how I was getting the title of the news headline because I assume you know how to do that. The place that is interesting is the SiteMapResolve function. I create a new node and set its parent to the current node, which successfully has the SiteMapPath show the correct breadcrumb:&lt;br /&gt;Home &gt; News &gt; A headline!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;strong&gt;A couple notes:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;First, I remove the handler once the page is complete because otherwise the function will get called every time the SiteMap resolves itself, which is not what we want!&lt;br /&gt;Second, you may need to touch the web.config (just remove a line and undo it) and save it to have your application recycle itself, otherwise your changes might not show up.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Hope this helps somebody. Happy Programming!!!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:Arial;&quot;&gt;&lt;strong&gt;Reference:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;a href=&quot;http://blog.lib.umn.edu/ayubx003/dividebyzero/2009/01/10/how_to_programmatically_add_no.html#more&quot;&gt;http://blog.lib.umn.edu/ayubx003/dividebyzero/2009/01/10/how_to_programmatically_add_no.html#more&lt;/a&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style=&quot;font-family:Arial;&quot;&gt;&lt;/span&gt;</description><link>http://vireshvshah.blogspot.com/2009/07/add-nodes-to-dynamically-to-sitemap-for.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-1393885759749092364</guid><pubDate>Thu, 09 Jul 2009 05:16:00 +0000</pubDate><atom:updated>2009-07-09T10:49:36.820+05:30</atom:updated><title>VS Debug Problem with IE8</title><description>&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;strong&gt;How VS debugger could be crashed with IE8?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If you opened multiple instances of IE8 and you attempt to debug your project, you mostly will have the issue where VS debugger just stops and ignores your break points!&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Why was that?&lt;br /&gt;&lt;br /&gt;Well, IE 8 has a feature called Loosely-Coupled Internet Explorer (LCIE) which results in IE running across multiple processes.&lt;br /&gt;&lt;/span&gt;&lt;a href=&quot;http://www.microsoft.com/windows/internet-explorer/beta/readiness/developers-existing.aspx#lcie&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;http://www.microsoft.com/windows/internet-explorer/beta/readiness/developers-existing.aspx#lcie&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;&lt;br /&gt;Older versions of the Visual Studio Debugger get confused by this and cannot figure out how to attach to the correct process.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;To overcome this issue, you need to disable the process growth feature of LCIE by follow the below steps:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;1) Open RegEdit&lt;br /&gt;2) Browse to HKEY_LOCALMACHINE -&gt; SOFTWARE -&gt; Microsoft -&gt; Internet Explorer -&gt; Main&lt;br /&gt;3) Add a dword under this key called TabProcGrowth&lt;br /&gt;4) Set TabProcGrowth to 0&lt;br /&gt;&lt;br /&gt;If you run into the same problem on Vista or newer, you will also need to turn off protected mode.&lt;br /&gt;&lt;br /&gt;And then go a head and start debugging your code :)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reference:&lt;/strong&gt;&lt;br /&gt;&lt;a href=&quot;http://weblogs.asp.net/abdullaabdelhaq/archive/2009/06/01/VS-Debug-Problem-with-IE8.aspx&quot;&gt;http://weblogs.asp.net/abdullaabdelhaq/archive/2009/06/01/VS-Debug-Problem-with-IE8.aspx&lt;/a&gt;&lt;/span&gt;</description><link>http://vireshvshah.blogspot.com/2009/07/vs-debug-problem-with-ie8.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-5449836927411279999</guid><pubDate>Thu, 30 Apr 2009 10:48:00 +0000</pubDate><atom:updated>2009-04-30T16:20:47.399+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Handle Errors in AJAX</category><category domain="http://www.blogger.com/atom/ns#">Handling Errors with the UpdatePanel control</category><title>Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX</title><description>&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Luis Abreu is an ASP.NET MVP who &lt;/span&gt;&lt;a href=&quot;http://msmvps.com/blogs/luisabreu/default.aspx&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;has a great blog&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; on the &lt;/span&gt;&lt;a href=&quot;http://msmvps.com/blogs/default.aspx&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;http://msmvps.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; blog site. Earlier today he &lt;/span&gt;&lt;a href=&quot;http://msmvps.com/blogs/luisabreu/archive/2006/10/29/UpdatePanel_3A00_-having-fun-with-errors.aspx&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;posted a great tutorial post&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; that describes how to use some of the new features in the &lt;/span&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2006/10/20/ASP.NET-AJAX-Beta-1-Released.aspx&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;ASP.NET AJAX Beta1 release&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; to add more robust error handling into your application. I highly recommend reading and bookmarking it for future use.&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Error handling in an AJAX world can often be tricky -- especially when AJAX call-backs are taking place and a mixture of client and server code is running within an application. In its most recent release, the &lt;?xml:namespace prefix = asp /&gt;&lt;asp:updatepanel&gt;control that comes with ASP.NET AJAX now has much more robust error handling and reporting features for you to use. &lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Specifically:&lt;br /&gt;1) You can now handle the &quot;OnAsyncPostBackError&quot; event on the &lt;asp:scriptmanager&gt;control to catch and/or modify an error message that occurs during the processing of an AJAX postback callback on the server.&lt;br /&gt;2) You can now set the &quot;AllowCustomErrors&quot; property on the &lt;asp:scriptmanager&gt;control to enable the standard ASP.NET custom error support to be enabled to redirect a user automatically to an error page when an error occurs (even if it is happening during an AJAX postback).&lt;br /&gt;3) You can now optionally handle client-side JavaScript events on the page to intercept any error message sent back from the server, and perform custom client-side actions as a result (for example: to output the error message to a nicely formatted section instead of performing a pop-up message).&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/span&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Read all about how to take advantage of the above new features from &lt;/span&gt;&lt;a href=&quot;http://msmvps.com/blogs/luisabreu/archive/2006/10/29/UpdatePanel_3A00_-having-fun-with-errors.aspx&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Luis&#39; great tutorial here&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;.&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Hope this helps,&lt;/span&gt;&lt;/p&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Viresh Shah&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/span&gt;&lt;/asp:scriptmanager&gt;&lt;/asp:scriptmanager&gt;&lt;/asp:updatepanel&gt;</description><link>http://vireshvshah.blogspot.com/2009/04/tiptrick-handling-errors-with.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-7627702789602907191</guid><pubDate>Thu, 30 Apr 2009 10:25:00 +0000</pubDate><atom:updated>2009-04-30T16:21:40.140+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Track User Activity in ASP.NET</category><title>Tracking User Activity in ASP.NET</title><description>&lt;div align=&quot;justify&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Introduction&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;I like data. I go gaga over measurable metrics. Nothing makes me happier than storing information and then seeing it expressed in tables of numbers and colorful charts. Whenever I work on a web application I am always looking for interesting data to record and analyze, and the most interesting (and potentially profitable) data that every website owner should track are usage statistics. Web server log files and online tools like &lt;/span&gt;&lt;a href=&quot;http://www.google.com/analytics/&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Google Analytics&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; provide an array of useful metrics, including how many unique visitors accessed your site, what pages were the most popular, what days of the week and hours of the day represent peak demand, and so forth. &lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Many ASP.NET web applications support user accounts, enabling visitors to create an account and sign in to the site. With a little bit of effort you can track the activity of your logged on users. This can include recording activities such as what pages were visited as well as what actions were performed. Consider a page that allows a user to manage his profile. When first arriving at this page the activity log might add an entry like &quot;Visiting the User Profile page.&quot; After updating his e-mail address, the activity log might record, &quot;Changed e-mail address from scott@example.com to mitchell@example.com.&quot; Such usage tracking offers a deeper level of analysis than is possible with log files or online visitor statistic tools. Instead of data that report total number of visitors or how the average user is interacting with the site, user activity tracking can provide a very detailed view of how a particular individual is using the application and what actions he is performing while signed on to the site. &lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;This article examines how to record your users&#39; activities in a database table and display this information in a web page. A complete, working demo application that shows these techniques in action is available for download.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;ASP.NET&#39;s &lt;/span&gt;&lt;a href=&quot;http://aspnet.4guysfromrolla.com/articles/120705-1.aspx&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Membership system&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; makes it easy to create and manage user accounts. Many websites that use Membership are configured to use &lt;/span&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider.aspx&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;SqlMembershipProvider&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;, a Membership provider that ships with the .NET Framework and stores user account information in a Microsoft SQL Server database. The demo application for this article uses SqlMembershipProvider, storing user account information along with the user activity log in a &lt;/span&gt;&lt;a href=&quot;http://www.microsoft.com/express/sql/default.aspx&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Microsoft SQL Server 2008 Express Edition&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; database file (ASPNETDB.mdf), which you will find in the application&#39;s App_Data folder. &lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;strong&gt;A Look at the Membership System&#39;s User Tracking Implementation&lt;/strong&gt; &lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;One of the lesser known features of ASP.NET&#39;s Membership system is that it has a built-in mechanism to track the last date and time each user has accessed the system. Each user account has a &lt;/span&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.lastactivitydate.aspx&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;LastActivityDate property&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; that records this information; the SqlMembershipProvider stores this value in the aspnet_Users table&#39;s LastActivityDate column in &lt;/span&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Coordinated_universal_time&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Coordinated Universal Time (UTC).&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; This LastActivityDate value is automatically updated whenever a user signs in and whenever their user account information is accessed via the &lt;/span&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.security.membership.getuser.aspx&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Membership.GetUser method&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;. The LastActivityDate is used by the Membership system to determine how many users are online - the &lt;/span&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.security.membership.getnumberofusersonline.aspx&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Membership.GetNumberOfUsersOnline method&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; returns the number of users whose LastActivityDate is within a certain window of the current date and time (15 minutes, by default).&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;The Membership system&#39;s user tracking implementation is pretty limited as it only specifies the last date and time a user was active on the site. It does not indicate what the user was doing at that time or provide any sort of activity history. The activity logging system presented in this article overcomes these limitations.&lt;/span&gt;&lt;/div&gt;&lt;a name=&quot;Designing_the_User_Activity_Log_Database_Table&quot;&gt;&lt;/a&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;strong&gt;Designing the User Activity Log Database Table&lt;/strong&gt; &lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;The first step in building any analysis tool is to determine what information to track. Different website usage analytic tools capture different information: web server logs typically record the filename of each requested page, the querystring, the date and time, and the HTTP status code, whereas online tools capture information of interest to the sales and marketing departments: visit durations, the geographical locations of the site&#39;s visitors, the number of unique visitors, entry and exit pages, and so on. &lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;What information do we need to record when tracking the online activity of a website&#39;s logged on users? At a minimum we would need to log:&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;The activity being performed&lt;br /&gt;The user performing the activity&lt;br /&gt;The date and time of activity&lt;br /&gt;The page being visited when the activity is performed&lt;br /&gt;&lt;br /&gt;The ActivityLogID is of type uniqueidentifier and uniquely identifies each log entry. The UserId column identifies the user who performed the activity. (The UserId column in the aspnet_Users table is what uniquely identifies each user in the SqlMembershipProvider user store.) The Activity column describes the activity performed; PageUrl is the URL of the page where the activity was performed. Finally, ActivityDate is the date and time (in UTC) that the activity was performed.&lt;br /&gt;The ActivityLog table is designed to have a record added for each activity performed by the user. Depending on the popularity of your website, this table can grow to include tens of thousands if not millions of records. You may want to consider implementing some mechanism to remove records older than a certain date, such as all activity log entries more than three months old. This could be accomplished by a SQL Job that executes nightly.&lt;/span&gt;&lt;/div&gt;&lt;a name=&quot;Logging_User_Activity&quot;&gt;&lt;/a&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Logging User Activity Web server log files automatically record each requested page; online usage statistic tools use cookies to track the pages users visit. Both of these logging mechanisms, once setup and configured, track visits to the site automatically without needed intervention from the web developer. The activity log is more flexible as it can be used to track any &quot;activity,&quot; which may be page visits or user-instigated actions. Therefore, logging a user activity to the database involves writing code.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;To help facilitate this process I created a custom base page class named BasePage that extends the System.Web.UI.Page class. BasePage includes a method named LogActivity(activity, recordPageUrl) that writes a record to the ActivityLog table with the specified activity and, if specified, the URL of the currently visited page.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;The LogActivity method&#39;s code follows:&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;protected void LogActivity(string activity, bool recordPageUrl)&lt;br /&gt;{&lt;br /&gt;if (Request.IsAuthenticated)&lt;br /&gt;{&lt;br /&gt;// Get information about the currently logged on user&lt;br /&gt;MembershipUser currentUser = Membership.GetUser(false);&lt;br /&gt;if (currentUser != null)&lt;br /&gt;{&lt;br /&gt;Guid userId = (Guid)currentUser.ProviderUserKey;&lt;br /&gt;// Log the activity in the database&lt;br /&gt;using (SqlConnection myConnection = new&lt;br /&gt;SqlConnection(ConfigurationManager.&lt;br /&gt;ConnectionStrings[&quot;MembershipConnectionString&quot;].ConnectionString))&lt;br /&gt;{&lt;br /&gt;SqlCommand myCommand = new SqlCommand();&lt;br /&gt;myCommand.CommandText = &quot;usp_LogUserActivity&quot;;&lt;br /&gt;myCommand.CommandType = CommandType.StoredProcedure;&lt;br /&gt;myCommand.Connection = myConnection;&lt;br /&gt;myCommand.Parameters.AddWithValue(&quot;@UserId&quot;, userId);&lt;br /&gt;myCommand.Parameters.AddWithValue(&quot;@Activity&quot;, activity);&lt;br /&gt;if (recordPageUrl)&lt;br /&gt;myCommand.Parameters.AddWithValue(&quot;@PageUrl&quot;, Request.RawUrl);&lt;br /&gt;else&lt;br /&gt;myCommand.Parameters.AddWithValue(&quot;@PageUrl&quot;, DBNull.Value);&lt;br /&gt;myConnection.Open();&lt;br /&gt;myCommand.ExecuteNonQuery();&lt;br /&gt;myConnection.Close();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The method starts by determining if the user visiting the page is authenticated. If so, it gets the user&#39;s information via the Membership class&#39;s GetUser method. If a user is returned, the stored procedure usp_LogUserActivity is called, passing in values for the @UserId, @Activity, and @PageUrl parameters. Note that if recordPageUrl is false, the @PageUrl parameter is set to a database NULL value; if it is true, the @PageUrl parameter is assigned the raw URL of the currently requested page, which includes the directories, filename, and querystring of the requested web page (i.e., /MyApp/Users/Default.aspx?ID=2).&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;The usp_LogUserActivity stored procedure starts by updating the LastActivityDate column in the aspnet_Users table. As a result, adding an entry to the user activity log is tantamount to retrieving the user&#39;s information through the Membership system. Following the update to the LastActivityDate, the usp_LogUserActivity stored procedure inserts a record into the ActivityLog table. This update and insert are atomic as they are performed under the umbrella of a transaction. For background on transactions and using SQL Server&#39;s TRY...CATCH blocks see &lt;/span&gt;&lt;a href=&quot;http://aspnet.4guysfromrolla.com/articles/072705-1.aspx&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Maintaining Database Consistency with Transactions&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; and &lt;/span&gt;&lt;a href=&quot;http://www.4guysfromrolla.com/webtech/041906-1.shtml&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;TRY...CATCH in SQL Server&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;ALTER PROCEDURE dbo.usp_LogUserActivity&lt;br /&gt;(&lt;br /&gt;@UserId uniqueidentifier,&lt;br /&gt;@Activity nvarchar(100),&lt;br /&gt;@PageUrl nvarchar(100)&lt;br /&gt;)&lt;br /&gt;AS&lt;br /&gt;BEGIN TRY&lt;br /&gt;BEGIN TRANSACTION -- Start the transaction&lt;br /&gt;DECLARE @CurrentTimeUtc datetime&lt;br /&gt;SET @CurrentTimeUtc = getutcdate()&lt;br /&gt;-- Update the LastActivityDate in aspnet_Users&lt;br /&gt;UPDATE dbo.aspnet_Users&lt;br /&gt;SET LastActivityDate = @CurrentTimeUtc&lt;br /&gt;WHERE @UserId = UserId&lt;br /&gt;-- Insert activity record for user&lt;br /&gt;INSERT INTO ActivityLog(UserId, Activity, PageUrl, ActivityDate)&lt;br /&gt;VALUES(@UserId, @Activity, @PageUrl, @CurrentTimeUtc)&lt;br /&gt;-- If we reach here, success!&lt;br /&gt;COMMIT&lt;br /&gt;END TRY&lt;br /&gt;BEGIN CATCH&lt;br /&gt;-- Whoops, there was an error&lt;br /&gt;IF @@TRANCOUNT &gt; 0&lt;br /&gt;ROLLBACK&lt;br /&gt;-- Raise an error with the details of the exception&lt;br /&gt;DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int&lt;br /&gt;SELECT @ErrMsg = ERROR_MESSAGE(),&lt;br /&gt;@ErrSeverity = ERROR_SEVERITY()&lt;br /&gt;RAISERROR(@ErrMsg, @ErrSeverity, 1)&lt;br /&gt;END CATCH&lt;br /&gt;&lt;br /&gt;With the BasePage class complete, the final step is to have the ASP.NET pages in the site derive from BasePage (rather than from System.Web.UI.Page). Once this has been done you can call the LogActivity method from any page. For example, the homepage (~/Default.aspx) has the following code for its Page_Load event handler:&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;if (!Page.IsPostBack)&lt;br /&gt;{&lt;br /&gt;base.LogActivity(&quot;Visiting the homepage...&quot;, true);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The LogActivity method can be called from any event handler in those ASP.NET pages that derive from BasePage. Call LogActivity from the Page_Load event handler to log information when a page is first visited. You can additionally call LogActivity when the user clicks a button to log that they&#39;ve performed a particular action (such as editing or deleting a record from some database table). All of the ASP.NET pages in the demo application derive from the BasePage class, and most include at least one call to the LogActivity method.&lt;/span&gt;&lt;a name=&quot;Displaying_a_Particular_User&#39;s_Activity_History&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Displaying a Particular User&#39;s Activity History The activity log provides a complete history of each user&#39;s activity on the site. The demo application includes a page named ActivityHistoryByUser.aspx that displays the complete history in a paged grid for a particular user. &lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;The GridView controls used in the web pages in this tutorial use default paging, which is easy to implement but inefficient when paging through a large number of records. Because the activity log may contain thousands of records for each user account, the GridView controls should be retooled to use custom paging unless some mechanism is put into place to periodically cull old activity log entries from the table or if only recent activity log records are displayed in the grid. For more information on custom paging see &lt;/span&gt;&lt;a href=&quot;http://aspnet.4guysfromrolla.com/articles/031506-1.aspx&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Custom Paging in ASP.NET&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Each activity in the left column is displayed as a hyperlink that links to the activity&#39;s PageUrl value (if such a value exists). The Last Updated column shows the date the activity was performed. For activities older than a week, the date the activity was performed is displayed. If the activity occurred more recently then a human-friendly message, such as &quot;2 days ago&quot; or &quot;6 minutes ago,&quot; is displayed in place of the date and time. (This display formatting is handled by the FormatLastUpdatedDate method in the BasePage class.) &lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;The grid is populated by the records returned from the usp_GetUserActivityLog stored procedure. As the following markup shows, this stored procedure returns the ActivityLog entries for a particular user ordered from the most recent entries to the oldest.&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;ALTER PROCEDURE dbo.usp_GetUserActivityLog&lt;br /&gt;(&lt;br /&gt;@UserID uniqueidentifier&lt;br /&gt;)&lt;br /&gt;AS&lt;br /&gt;DECLARE @CurrentDateUtc datetime&lt;br /&gt;SET @CurrentDateUtc = getutcdate()&lt;br /&gt;SELECT ActivityLogID, Activity, PageUrl, ActivityDate, @CurrentDateUtc as CurrentDate&lt;br /&gt;FROM ActivityLog&lt;br /&gt;WHERE UserID = @UserID&lt;br /&gt;ORDER BY ActivityDate DESC&lt;br /&gt;&lt;/span&gt;&lt;a name=&quot;Viewing_the_Online_Users_and_their_Last_Performed_Activity&quot;&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Viewing the Online Users and their Last Performed Activity Many websites that support user accounts have a page that lists what users are currently online and what activity they last performed. As noted earlier, the Membership system automatically records each user&#39;s last active date and time and provides a method for determining how many users have been active within a specified time window. The Membership&#39;s built-in system does not include what activity the user last performed, but this information is captured by the ActivityLog table.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;I added a stored procedure to the database named usp_GetCurrentActivityForOnlineUsers that returns the list of users who are currently online along with their most recent activity. This stored procedure takes in a single input parameter, @MinutesSinceLastInactive, which is the number of minutes that has elapsed since a user has been active in the system and is still considered &quot;online.&quot; For example, a value of 15 means that any user whose LastActivityDate is within 15 minutes of the current date and time is considered &quot;online,&quot; whereas those users whose LastActivityDate is outside of this window are considered &quot;offline.&quot;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;The usp_GetCurrentActivityForOnlineUsers stored procedure starts by determining what time is the cutoff for a user to be considered &quot;online.&quot; It then queries the aspnet_Users and ActivityLog tables to retrieve the username of online users along with information about their last activity.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;ALTER PROCEDURE&lt;br /&gt;dbo.usp_GetCurrentActivityForOnlineUsers&lt;br /&gt;(&lt;br /&gt;@MinutesSinceLastInactive int&lt;br /&gt;)&lt;br /&gt;AS&lt;br /&gt;DECLARE @CurrentTimeUtc datetime&lt;br /&gt;SET @CurrentTimeUtc = getutcdate()&lt;br /&gt;DECLARE @DateActive datetime&lt;br /&gt;SELECT @DateActive = DATEADD(minute, -(@MinutesSinceLastInactive), @CurrentTimeUtc)&lt;br /&gt;SELECT act.UserId,&lt;br /&gt;u.UserName,&lt;br /&gt;act.Activity,&lt;br /&gt;act.PageUrl,&lt;br /&gt;act.ActivityDate,&lt;br /&gt;@CurrentTimeUtc as CurrentDate&lt;br /&gt;FROM dbo.aspnet_Users u(NOLOCK)&lt;br /&gt;INNER JOIN dbo.ActivityLog act(NOLOCK) ON&lt;br /&gt;act.UserId = u.UserId&lt;br /&gt;WHERE u.LastActivityDate &gt; @DateActive AND&lt;br /&gt;act.ActivityDate = u.LastActivityDate&lt;br /&gt;ORDER BY act.ActivityDate DESC&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Web server log files and online usage analysis tools are helpful in determining and evaluating macroscopic usage patterns. Unfortunately, these tools cannot provide a detailed view of how a particular user is interacting with your site. Nor can they provide live, up to the second activity information that can be used in your application to show who is currently online and what they are doing. Such deep usage analysis and real-time statistics are possible on websites that support user accounts.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;ASP.NET&#39;s Membership system greatly simplifies the process of setting up, creating, and managing user accounts. However, the Membership system only tracks when each user&#39;s last activity was on the site; it does not log the activity performed or maintain an activity history. As examined in this article, it is possible to build your own user activity log with a little bit of elbow grease.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Happy Programming!&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;strong&gt;Reference:&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;a href=&quot;http://dotnetslackers.com/articles/aspnet/Tracking-User-Activity.aspx&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;http://dotnetslackers.com/articles/aspnet/Tracking-User-Activity.aspx&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;</description><link>http://vireshvshah.blogspot.com/2009/04/tracking-user-activity.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-1621529996217862648</guid><pubDate>Sat, 07 Feb 2009 08:35:00 +0000</pubDate><atom:updated>2009-02-07T14:14:20.123+05:30</atom:updated><title>Copy/Insert row from one sheet to another sheet in Excel using Interop.Excel in .NET</title><description>&lt;div align=&quot;justify&quot;&gt;I was just trying to copy row in one excel file to another excel using Interop.Excel from .NET. I tried a lot but couldn&#39;t make it. It looks very simple at first view but normal Rows.Insert doesn&#39;t work in all cases. I googled a lot and then after a long time I found one solution to achieve this.&lt;br /&gt;&lt;br /&gt;Have a look at following code to achieve this(if you&#39;re using interop.excel).&lt;br /&gt;&lt;br /&gt;Dim xlApplication As New Excel.Application&lt;br /&gt;xlApplication.Visible = False&lt;br /&gt;Dim xlBook As Workbook&lt;br /&gt;Dim xlBook_New As Workbook&lt;br /&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;Try&lt;br /&gt;&lt;/div&gt;&lt;div align=&quot;justify&quot;&gt;xlBook = xlApplication.Workbooks.Open(&quot;C:\Source.xls&quot;)&lt;br /&gt;xlBook_New = xlApplication.Workbooks.Open(&quot;C:\Destination.xls&quot;)&lt;br /&gt;&lt;br /&gt;xlBook.Worksheets(&quot;&quot; &amp;amp; &quot;Sheet1&quot; &amp;amp; &quot;&quot;).activate()&lt;br /&gt;Dim xlSheet1 As Worksheet = xlBook.ActiveSheet&lt;br /&gt;xlSheet1.Range(&quot;A1&quot;, &quot;CP5&quot;).Select()&lt;br /&gt;xlSheet1.Range(&quot;A1&quot;, &quot;CP5&quot;).Copy()&lt;br /&gt;xlApplication.Selection.copy()&lt;br /&gt;xlBook_New.Worksheets(&quot;Sheet1&quot;).activate()&lt;br /&gt;Dim xlSheet1_new As Worksheet = xlBook_New.ActiveSheet&lt;br /&gt;xlSheet1_new.Activate()&lt;br /&gt;Dim rng As Excel.Range = xlSheet1_new.Range(&quot;A2&quot;)&lt;br /&gt;rng.EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromRightOrBelow)&lt;br /&gt;&lt;br /&gt;&#39;Remove 3rd row&lt;br /&gt;Dim rng1 As Excel.Range = xlSheet1_new.Range(&quot;A1&quot;).Offset(3, 0)&lt;br /&gt;rng1.EntireRow.Delete(XlDeleteShiftDirection.xlShiftUp)&lt;br /&gt;&lt;br /&gt;xlSheet1_new.Name = &quot;Sheet1&quot;&lt;br /&gt;xlSheet1_new.Columns.AutoFit()&lt;br /&gt;&lt;br /&gt;Catch ex As Exception&lt;br /&gt;MsgBox(ex.Message)&lt;br /&gt;Finally&lt;br /&gt;Dim o As New Object&lt;br /&gt;Clipboard.SetDataObject(0)&lt;br /&gt;xlBook.Save()&lt;br /&gt;xlBook.Close(False, Nothing, False)&lt;br /&gt;xlBook = Nothing&lt;br /&gt;xlBook_New.Save()&lt;br /&gt;&#39; Need all following code to clean up and remove all references!!!&lt;br /&gt;xlBook_New.Close(Nothing, Nothing, Nothing)&lt;br /&gt;xlBook_New = Nothing&lt;br /&gt;xlApplication.Workbooks.Close()&lt;br /&gt;xlApplication.Quit()&lt;br /&gt;xlApplication = Nothing&lt;br /&gt;End Try&lt;br /&gt;&lt;br /&gt;Happy Programming!!!&lt;/div&gt;</description><link>http://vireshvshah.blogspot.com/2009/02/copy-row-from-one-sheet-to-another.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-5231629986992414222</guid><pubDate>Sat, 31 Jan 2009 08:11:00 +0000</pubDate><atom:updated>2009-01-31T13:58:38.034+05:30</atom:updated><title>All about Application Root in ASP.NET</title><description>&lt;div align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;It still surprises me how many ASP.NET developers I run into don&#39;t know about the different ways to construct path references in ASP.NET. Let&#39;s say we want to include an image in our website. This image is hosted on our website, in an &quot;img&quot; subfolder off of the application root. So how do we create the image HTML, and what do we use as the URL? The wrong answer can lead to big-time maintenance headaches later.&lt;br /&gt;&lt;br /&gt;There are three kinds of paths we can use:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Absolute&lt;br /&gt;Relative&lt;br /&gt;Application root (ASP.NET only)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Additionally, we have a few choices on how we chose to create the image in our ASP.NET page:&lt;br /&gt;&lt;br /&gt;Plain ol&#39; HTML&lt;br /&gt;HTML server control&lt;br /&gt;Web server control&lt;br /&gt;Each kind of path can be used for each rendering object type (HTML, server control). It turns out that the path is much more important than the rendering object, as different forces might lend me to use controls over HTML. For posterity, I&#39;ll just pick plain ol&#39; HTML as an example.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;strong&gt;Absolute&lt;br /&gt;&lt;/strong&gt;Absolute paths are fully qualified URL paths that include the domain name in the URL:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;Absolute paths work great for external resources outside of my website, but are poor choices for internal resources. Typically ASP.NET development is done on a development machine, and deployed to a different machine, which means the URLs will most likely change.&lt;br /&gt;&lt;br /&gt;For example, the URL above works on my local machine, but breaks when deployed to the server because the &quot;EcommApp&quot; now resides at the root, so I need a URL like &quot;http://ecommapp.com/img/blarg.jpg&quot;. Since this absolute path is different, my link breaks, and I have to make lots of changes going back and forth between production and development. For internal resources, absolute paths won&#39;t work.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Relative&lt;/strong&gt;&lt;br /&gt;Relative paths don&#39;t specify the domain name, and come in a few flavors:&lt;br /&gt;&lt;br /&gt;Site-root relative&lt;br /&gt;Current page relative&lt;br /&gt;Peer relative&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;These URL path notations are similar to file path notations. Each is slightly different and carries its own issues.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Site-root relative&lt;/strong&gt;&lt;br /&gt;Here&#39;s the same img tag used before, now with a site-root relative path:&lt;br /&gt;&lt;br /&gt;Note the lack of the domain name and the leading slash, that&#39;s what makes this a site-root relative path. These paths are resolved against the current domain, which means I can go from &quot;localhost&quot; to &quot;ecommapp.com&quot; with ease.&lt;br /&gt;&lt;br /&gt;Again, the problem I run into is that locally, my app is deployed off of an &quot;EcommApp&quot; folder, but on the server, it&#39;s deployed at the root. My image breaks again, so site-root relative paths aren&#39;t a great choice, either.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Current page relative&lt;/strong&gt;&lt;br /&gt;Now the img tag using a current page relative path:&lt;br /&gt;&lt;br /&gt;This time, I don&#39;t have the leading slash, nor do I include the &quot;EcommApp&quot; folder. This is because current page relative paths are constructed off the URL being requested, which in this case is the &quot;default.aspx&quot; page at the root of the application. The request goes from the &quot;default.aspx&quot; path, wherever that might be. Now my URL does not have to change when I deploy to production, it works in both places.&lt;br /&gt;&lt;br /&gt;But I have two problems now:&lt;br /&gt;&lt;br /&gt;Moving the page means I have to change all of the resource URLs&lt;br /&gt;Creating a page in a subfolder means all URLs to the same resource could be different&lt;br /&gt;This leads me to the last kind of relative path.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Peer relative&lt;/strong&gt;&lt;br /&gt;Suppose I want to create the img tag in a site with the following structure:&lt;br /&gt;&lt;br /&gt;\Root&lt;br /&gt;\img&lt;br /&gt;blarg.jpg&lt;br /&gt;\products&lt;br /&gt;default.aspx&lt;br /&gt;Note that default.aspx has to go up one node, then down one node to reference the file in the above tree. Here&#39;s the img tag to do just that:&lt;br /&gt;&lt;br /&gt;Similar to folder paths, I use the &quot;..&quot; operator to climb up one node in the path, then specify the rest of the path. This path works just fine in production and development, but I still have two main problems:&lt;br /&gt;&lt;br /&gt;URLs to the same resource are different depending on depth of the source file in the tree&lt;br /&gt;Moving a resource forces me to manually fix the relative paths&lt;br /&gt;If I decide to move the &quot;default.aspx&quot; page up one level, all of the relative paths must be manually fixed.&lt;br /&gt;&lt;br /&gt;But there&#39;s one more major issue.&lt;br /&gt;&lt;br /&gt;User controls&lt;br /&gt;Now let&#39;s suppose I have the following setup:&lt;br /&gt;&lt;br /&gt;\Root&lt;br /&gt;\img&lt;br /&gt;blarg.jpg&lt;br /&gt;\products&lt;br /&gt;default.aspx&lt;br /&gt;\user&lt;br /&gt;login.aspx&lt;br /&gt;\support&lt;br /&gt;help.aspx&lt;br /&gt;\usercontrols&lt;br /&gt;header.ascx&lt;br /&gt;default.aspx&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;All of the ASPX files use the same &quot;header.ascx&quot; control (I&#39;m not using master pages on this site). The &quot;header.ascx&quot; control needs to reference the img, but note that the relative path is calculated based on the page requested, not the user control requested. This means that the relative URL will only work if the user control just happens to be included in a page at the correct depth. All other times it will break, and this is a huge problem.&lt;br /&gt;&lt;br /&gt;Luckily, ASP.NET includes a handy way to fix all of these problems, deployment and otherwise.&lt;br /&gt;&lt;br /&gt;Application root&lt;br /&gt;A path built with an application root is prefixed with a tilde (~). For example, here&#39;s a raw application path to the image:&lt;br /&gt;&lt;br /&gt;~/img/blarg.jpgNote the &quot;~/&quot; at the front, that&#39;s what signifies it as an application root path. Application root paths are constructed starting at the root of the application. For example, both &quot;http://ecommapp.com&quot; and &quot;http://localhost/EcommApp&quot; are application roots, so I don&#39;t have to worry about changing paths at deployment.&lt;br /&gt;&lt;br /&gt;Additionally, I don&#39;t have to worry about problems with node depth in the hierarchy, as paths are formed from the root and not relative to a leaf node, so my user control problem disappears.&lt;br /&gt;&lt;br /&gt;One issue with application root paths is only ASP.NET knows about them. Not browsers. If I do this:&lt;br /&gt;&lt;br /&gt;The image breaks, as browsers don&#39;t know what IIS applications are, they just know URLs. ASP.NET, however, will take this URL and generate the correct relative path for you, as long as I use ASP.NET to generate the path. Server controls, like &quot;asp:hyperlink&quot; can handle the application root path.&lt;br /&gt;&lt;br /&gt;To use the application root path in raw HTML, I just need to use the ResolveUrl method, which is included in the Control class, and therefore available in both my Page and UserControl classes. Combining raw HTML and the ResolveUrl method, I get:&lt;br /&gt;&lt;br /&gt;&quot; /&gt;The &quot;&lt;%= %&gt;&quot; construct is basically a &quot;Response.Write&quot;, and allows me to call the ResolveUrl method directly.&lt;br /&gt;&lt;br /&gt;Using application root paths allows me to:&lt;br /&gt;&lt;br /&gt;Develop locally and deploy to production seamlessly&lt;br /&gt;Have consistent URL per resource&lt;br /&gt;Use raw HTML without the problems of absolute and relative paths&lt;br /&gt;Some caveats&lt;br /&gt;No matter what I do, I have to change code if either the resource or the page moves. I can minimize the number of changes by externalizing the specific path (the &quot;~/img/blarg.jpg&quot; part) to a resource file, constant, or static global variable. This applies for all types of paths, so I like to eliminate as much duplication as possible.&lt;br /&gt;&lt;br /&gt;It&#39;s dangerous to assume that the structure or names of resources and pages won&#39;t change at some point. As a web site grows, it can become necessary to move resources around and reorganize your site structure. To minimize the impact of deployment and change, use application paths as much as possible, you&#39;ll save on Excedrin later.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;strong&gt;Reference URL:&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;a href=&quot;http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/01/03/application-root-is-your-friend.aspx&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/01/03/application-root-is-your-friend.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; &lt;/span&gt;&lt;/div&gt;</description><link>http://vireshvshah.blogspot.com/2009/01/all-about-application-root-in-aspnet.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-3603267132582783061</guid><pubDate>Tue, 27 Jan 2009 04:38:00 +0000</pubDate><atom:updated>2009-01-31T14:00:23.403+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">ASP.NET Performance</category><category domain="http://www.blogger.com/atom/ns#">Optimize Webpage</category><category domain="http://www.blogger.com/atom/ns#">Viewstate Compression</category><title>ViewState Compression</title><description>&lt;div align=&quot;justify&quot;&gt;Recently, I developed a huge ASP.NET page, with more than 30 controls. As we all know, it&#39;s a good idea to disable the ViewState for the controls that don&#39;t actually need it, say Literals or Labels. After doing that, I noticed that the hidden ViewState field was still a few KBs big. This is obviously a big problem for the users that still don&#39;t have a broadband connection, because uploading 40 KB to the server is really a bad issue, especially when they begin to click the &quot;Submit&quot; button again and again because they don&#39;t notice any response. So, after a few searches through the Internet, I got a code which compresses viewstate and therefore save a rough 50% of the bandwidth.&lt;br /&gt;&lt;br /&gt;Performance and Conclusion:&lt;br /&gt;&lt;br /&gt;I noticed that the ViewState has been reduced from 38 KB to 17 KB, saving 44%. Supposing you have an average of 1 postback per minute per user, you could save more than 885 MB of bandwidth per month on every single user. That&#39;s an excellent result: you save bandwidth (and therefore money), and the user notices a shorter server response time.&lt;br /&gt;&lt;br /&gt;I wanted to point out that this solution has a performance hit on the server&#39;s hardware. Compressing, decompressing, encoding, and decoding data is quite a heavy work for the server, so you have to balance the number of users with your CPU power and RAM.&lt;br /&gt;&lt;br /&gt;Reference URL: &lt;a href=&quot;http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx&quot;&gt;http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx&lt;/a&gt;&lt;/div&gt;</description><link>http://vireshvshah.blogspot.com/2009/01/viewstate-compression.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-110778182955953940.post-2895825463921478638</guid><pubDate>Thu, 16 Oct 2008 05:07:00 +0000</pubDate><atom:updated>2009-01-31T14:00:45.121+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Display Image in asp.net</category><category domain="http://www.blogger.com/atom/ns#">Thumbnailer HTTP Handler</category><category domain="http://www.blogger.com/atom/ns#">Thumbnailer in asp.net</category><title>Thumbnailer HTTP Handler</title><description>&lt;div align=&quot;justify&quot;&gt;The implementation was to create an image optimizer control that would scale and optimize the quality of the original uploaded image and store the results to a data store (in this case a hard disk), and create an HTTP handler that would create thumbnail images of the optimized images on the fly, at runtime, and in memory (no physical disk space to store the temporary thumbnail file). Following is the code, which displays images either from database or from session. &lt;/div&gt;&lt;p align=&quot;justify&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:arial;font-size:78%;&quot;&gt;&lt;%@ WebHandler Language=&quot;C#&quot; Class=&quot;Handler.Thumbnailer&quot; %&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Reflection;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Net;&lt;br /&gt;using System.Web.SessionState;&lt;br /&gt;namespace Handler&lt;br /&gt;{&lt;br /&gt;public class Thumbnailer : IHttpHandler, IRequiresSessionState&lt;br /&gt;{&lt;br /&gt;#region Enumerations&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// An internal enumeration defining the thumbnail sizes.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;internal enum ThumbnailSizeType&lt;br /&gt;{&lt;br /&gt;Small = 72,&lt;br /&gt;Medium = 144,&lt;br /&gt;Large = 288&lt;br /&gt;}&lt;br /&gt;#endregion Enumerations&lt;br /&gt;#region Fields&lt;br /&gt;// Declare and define global constants&lt;br /&gt;private const string IMG_PARAM = &quot;img&quot;; // image parameter&lt;br /&gt;private const string SIZE_PARAM = &quot;size&quot;; // size parameter&lt;br /&gt;// Declare and define default values to class member variables&lt;br /&gt;private ThumbnailSizeType _sizeType = ThumbnailSizeType.Small;&lt;br /&gt;#endregion Fields&lt;br /&gt;#region Methods&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Sets the size of the thumbnail base on the size parameter.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;/// &lt;param name=&quot;size&quot;&gt;The size parameter.&lt;/param&gt;&lt;br /&gt;private void SetSize(string size)&lt;br /&gt;{&lt;br /&gt;int sizeVal;&lt;br /&gt;if (!Int32.TryParse(size.Trim(), System.Globalization.NumberStyles.Integer, null, out sizeVal))&lt;br /&gt;sizeVal = (int)ThumbnailSizeType.Small;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;this._sizeType = (ThumbnailSizeType)sizeVal;&lt;br /&gt;}&lt;br /&gt;catch&lt;br /&gt;{&lt;br /&gt;this._sizeType = ThumbnailSizeType.Small;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Processs the incoming HTTP request.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;/// &lt;param name=&quot;context&quot;&gt;Context.&lt;/param&gt;&lt;br /&gt;public void ProcessRequest(HttpContext context)&lt;br /&gt;{&lt;br /&gt;if (string.IsNullOrEmpty(context.Request.QueryString[SIZE_PARAM]))&lt;br /&gt;this._sizeType = ThumbnailSizeType.Small;&lt;br /&gt;int _imageId = 0;&lt;br /&gt;if (context.Request.QueryString[&quot;img&quot;] != null)&lt;br /&gt;_imageId = Convert.ToInt32(context.Request.QueryString[&quot;img&quot;]);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if (_imageId != 0)&lt;br /&gt;{&lt;br /&gt;//Fetch your data from database containing byte array&lt;br /&gt;Byte[] b=your data;&lt;br /&gt;System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(b));&lt;br /&gt;context.Response.ContentType = &quot;image/jpeg&quot;;&lt;br /&gt;if (string.IsNullOrEmpty(context.Request.QueryString[SIZE_PARAM]))&lt;br /&gt;{&lt;br /&gt;img.Save(context.Response.OutputStream, ImageFormat.Jpeg);&lt;br /&gt;img.Dispose();&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;using (System.Drawing.Image tn = this.CreateThumbnail(img))&lt;br /&gt;{&lt;br /&gt;tn.Save(context.Response.OutputStream, ImageFormat.Jpeg);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;//Show image from memory.&lt;br /&gt;if (context.Session[&quot;Photo&quot;] != null)&lt;br /&gt;{&lt;br /&gt;System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(context.Session[&quot;Photo&quot;] as Byte[]));&lt;br /&gt;context.Response.ContentType = &quot;image/jpeg&quot;;&lt;br /&gt;using (System.Drawing.Image tn = this.CreateThumbnail(img))&lt;br /&gt;{&lt;br /&gt;tn.Save(context.Response.OutputStream, ImageFormat.Jpeg);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// This method generates the actual thumbnail.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;/// &lt;param name=&quot;src&quot;&gt;&lt;/param&gt;&lt;br /&gt;/// &lt;returns&gt;Thumbnail image&lt;/returns&gt;&lt;br /&gt;private System.Drawing.Image CreateThumbnail(System.Drawing.Image src)&lt;br /&gt;{&lt;br /&gt;int maxSize = (int)this._sizeType;&lt;br /&gt;int w = src.Width;&lt;br /&gt;int h = src.Height;&lt;br /&gt;if (h &lt;&gt; 1024) { h = 768; w = 1024; }&lt;br /&gt;if (h &lt;&gt; 800) { h = 800; w = 600; }&lt;br /&gt;if (w &gt; maxSize)&lt;br /&gt;{&lt;br /&gt;h = (h * maxSize) / w;&lt;br /&gt;w = maxSize;&lt;br /&gt;}&lt;br /&gt;if (h &gt; maxSize)&lt;br /&gt;{&lt;br /&gt;w = (w * maxSize) / h;&lt;br /&gt;h = maxSize;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Bitmap bitmap = new Bitmap(w, h);&lt;br /&gt;using (Graphics g = Graphics.FromImage(bitmap))&lt;br /&gt;{&lt;br /&gt;g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;&lt;br /&gt;g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;&lt;br /&gt;g.DrawImage(src, 0, 0, bitmap.Width, bitmap.Height);&lt;br /&gt;}&lt;br /&gt;return bitmap;&lt;br /&gt;// The third parameter is required and is of type delegate. Rather then create a method that&lt;br /&gt;// does nothing, .NET 2.0 allows for anonymous delegate (similar to anonymous functions in other languages).&lt;br /&gt;//return src.GetThumbnailImage(w, h, delegate() { return false; }, IntPtr.Zero);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#endregion Methods&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public bool IsReusable&lt;br /&gt;{&lt;br /&gt;get { return true; }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;strong&gt;Using This Code:&lt;/strong&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;1.Copy and paste this code in Thumbnailer.ashx file&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;2. You can display image either from Session or from database by passing img as querystring.&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;a. Using Session&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;Session[&quot;Photo&quot;]=Array of Image Bytes();&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;Image1.ImageURL=&quot;~/Thumbnailer.ashx&quot;;&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;b. Using img as querystring&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;Image1.ImageURL=&quot;~/Thumbnailer.ashx?img=1&quot;; // where 1 is id of image table containing image data&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;&lt;span style=&quot;font-family:arial;font-size:100%;&quot;&gt;Happy Coding!!!&lt;/span&gt;&lt;/p&gt;</description><link>http://vireshvshah.blogspot.com/2008/10/thumbnailer-http-handler.html</link><author>noreply@blogger.com (Viresh Shah)</author><thr:total>0</thr:total></item></channel></rss>