<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" 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" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;DEABR3Y4fCp7ImA9WhBaE04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523</id><updated>2013-05-24T00:49:16.834+05:30</updated><category term="node.js" /><category term="Cryptography" /><category term="iisnode" /><category term="Visual Studio" /><category term="URL Rewrite" /><category term="Book Review" /><category term="Twitter" /><category term="jQuery" /><category term="Performance" /><category term="MVC" /><category term="DNS" /><category term="SQL" /><category term="Download" /><category term="windows server 8" /><category term="Review" /><category term="knockout.js" /><category term="jQuery Mobile" /><category term="CTP" /><category term="Security" /><category term="IIS 8" /><category term="IIS" /><category term="C#.NET" /><category term="ASP.NET" /><category term="OpenID" /><category term="MVC 4" /><category term="Wait Stats" /><category term="Roslyn" /><category term="oAuth" /><category term="Featured" /><category term="Picture Post" /><category term="PowerShell" /><category term="NuGet" /><category term="SEO" /><category term="vNext" /><category term="Framework" /><category term="OData" /><category term="Interview Question" /><category term="JavaScript" /><category term="Facebook" /><category term="ASP.NET 4.5" /><title>dotnetExpertGuide.com</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://www.dotnetexpertguide.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>97</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/Dotnetexpertguide" /><feedburner:info uri="dotnetexpertguide" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-sa/2.0/" /><feedburner:emailServiceId>Dotnetexpertguide</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry gd:etag="W/&quot;CUACRns8fyp7ImA9WhBbEkg.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-2971598475317415673</id><published>2013-05-11T11:59:00.000+05:30</published><updated>2013-05-11T11:59:27.577+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-11T11:59:27.577+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: HandleError action filter</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-Lscfd1NvnVY/UY3iJLOwKmI/AAAAAAAABZ4/l4cZ6XcrllM/s1600/HandleError.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="ASP.NET MVC: HandleError" border="0" src="http://4.bp.blogspot.com/-Lscfd1NvnVY/UY3iJLOwKmI/AAAAAAAABZ4/l4cZ6XcrllM/s1600/HandleError.png" title="ASP.NET MVC: HandleError" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;HandleError attribute is used to catch unhandled exception in controller action method. In default MVC template, HandleError attribute is already added to GlobalFilterCollection. In MVC 3, we can see it in &lt;b&gt;Global.asax&lt;/b&gt; while in MVC 4 we can see it in &lt;b&gt;App_Start/FilterConfig.cs&lt;/b&gt;. One thing to keep in mind is that HandleError will handle exception only if customErrors mode="On" is set in web.config.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Attribute Usage:&lt;/b&gt; Controller &amp; method&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
&lt;div id="codeSnippet" class="csharpcode"&gt;&lt;pre class="alt"&gt;[HandleError]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Index()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Exception(&lt;span class="str"&gt;"HandleError Exception"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;As noted earlier, if we have not set  customErrors mode="On" then HandleError will not catch this exception and it will show default YSOD(Yellow Screen Of Death).&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-rquPUJfS4w0/UY3iMziRFGI/AAAAAAAABaA/_k-RsLIz6Io/s1600/YSOD-asp.net.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="YSOD(Yellow Screen Of Death) ASP.NETA" border="0" src="http://1.bp.blogspot.com/-rquPUJfS4w0/UY3iMziRFGI/AAAAAAAABaA/_k-RsLIz6Io/s1600/YSOD-asp.net.png" title="YSOD(Yellow Screen Of Death) ASP.NETA" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;To enable exception catching, enable customErrors in web.config as below.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&amp;lt;system.web&amp;gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;  &amp;lt;customErrors mode=&lt;span class="str"&gt;"On"&lt;/span&gt;&amp;gt;&amp;lt;/customErrors&amp;gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;lt;/system.web&amp;gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Now again run application, it should catch exception &amp; it should display error.cshtml as displayed below.&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-hwiLI2t3-LI/UY3iNxBypTI/AAAAAAAABaI/ZbIjS49xiCg/s1600/handleerror-aspnet-mvc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-hwiLI2t3-LI/UY3iNxBypTI/AAAAAAAABaI/ZbIjS49xiCg/s1600/handleerror-aspnet-mvc.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;With HandleError we can also specify &lt;b&gt;ExceptionType&lt;/b&gt; for which to catch unhandled exception, &lt;b&gt;View&lt;/b&gt; to display when exception is caught, and &lt;b&gt;Master&lt;/b&gt; view.&lt;/p&gt;
&lt;p&gt;Check out &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;ASP.NET MVC: Action filter series&lt;/a&gt; post to read about other available  action filters.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=lOT3hzhCOPg:DljDZuRC-_s:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=lOT3hzhCOPg:DljDZuRC-_s:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=lOT3hzhCOPg:DljDZuRC-_s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=lOT3hzhCOPg:DljDZuRC-_s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=lOT3hzhCOPg:DljDZuRC-_s:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=lOT3hzhCOPg:DljDZuRC-_s:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=lOT3hzhCOPg:DljDZuRC-_s:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=lOT3hzhCOPg:DljDZuRC-_s:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=lOT3hzhCOPg:DljDZuRC-_s:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/lOT3hzhCOPg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/2971598475317415673/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/05/aspnet-mvc-handleerror-action-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/2971598475317415673?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/2971598475317415673?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/lOT3hzhCOPg/aspnet-mvc-handleerror-action-filter.html" title="ASP.NET MVC: HandleError action filter" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-Lscfd1NvnVY/UY3iJLOwKmI/AAAAAAAABZ4/l4cZ6XcrllM/s72-c/HandleError.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/05/aspnet-mvc-handleerror-action-filter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkIMSX4-cCp7ImA9WhBWGU8.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-901977891312677723</id><published>2013-04-14T14:06:00.000+05:30</published><updated>2013-04-14T14:06:28.058+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-14T14:06:28.058+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Featured" /><category scheme="http://www.blogger.com/atom/ns#" term="Performance" /><title>ASP.NET Web Optimization Framework (Bundling &amp; Minification) Articles </title><content type="html">&lt;p&gt;Right from developer preview version of ASP.NET 4.5 &amp; MVC 4 (vNext), I have covered ASP.NET Web Optimization Framework (a.k.a Bundling &amp; Minification) in my &lt;a href="http://www.dotnetexpertguide.com/2011/09/aspnet-mvc-4-article-series.html"&gt;MVC 4 article series&lt;/a&gt;. Later on I have posted several articles covering different aspects of ASP.NET Web Optimization Framework and how I implemented it. So I'm writing this post as an index post of articles covering ASP.NET Web Optimization Framework. So it would be easier to access all posts under one roof. In upcoming days I'm planning to add few more articles on this topic, as and when I will add new articles I will update this index post as well.&lt;/p&gt;
&lt;p&gt;If you come across any good article on this topic then do comment here, I will include it in this list.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2011/12/bundling-and-minification-aspnet-mvc4.html"&gt;&lt;b&gt;Bundling and Minification in ASP.NET MVC 4&lt;/b&gt;&lt;/a&gt; This post cover how to use bundling &amp; minification in MVC 4 application.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-45-mvc-4-revisiting-IBundleTransform-in-bundling.html"&gt;&lt;b&gt;ASP.NET 4.5 &amp; MVC 4: Revisiting IBundleTransform&lt;/b&gt;&lt;/a&gt; In this article, we will discuss how to implement custom bundle transform with ASP.NET Web Optimization Framework. We will also discuss how to address caching with ASP.NET Web Optimization Framework.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-45-mvc-4-bundling-next-approach.html"&gt;&lt;b&gt;ASP.NET 4.5 &amp; MVC 4 Bundling: Next Approach&lt;/b&gt;&lt;/a&gt; Default bundle accepts file path as bundle input and bundle &amp; minimize it in one resource. This post describe how to pass additional parameter to custom bundle transform and how to utilize whilte processing custom bundle transform.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-bundling-auto-sync-javascript-model-with-mvc-model.html"&gt;&lt;b&gt;ASP.NET MVC Bundling: Auto sync JavaScript model with MVC model&lt;/b&gt;&lt;/a&gt; This post explain how to create custom bundle transform which is used to generate JavaScript Model from C# model class.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-web-optimization-framework-with-mvc3-aspnet-40-web-forms.html"&gt;&lt;b&gt;ASP.NET Web Optimization Framework with MVC 3 &amp; ASP.NET 4.0 web form&lt;/b&gt;&lt;/a&gt; ASP.NET Web Optimization Framework is built on top of ASP.NET 4.0. This article shows how to implement bundling &amp; minification in ASP.NET 4.0 web form &amp; MVC 3 application.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Qipim5YDNdY:FB4gAvivx10:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=Qipim5YDNdY:FB4gAvivx10:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Qipim5YDNdY:FB4gAvivx10:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Qipim5YDNdY:FB4gAvivx10:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Qipim5YDNdY:FB4gAvivx10:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=Qipim5YDNdY:FB4gAvivx10:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Qipim5YDNdY:FB4gAvivx10:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Qipim5YDNdY:FB4gAvivx10:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=Qipim5YDNdY:FB4gAvivx10:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/Qipim5YDNdY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/901977891312677723/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/04/aspnet-web-optimization-framework-article-series.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/901977891312677723?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/901977891312677723?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/Qipim5YDNdY/aspnet-web-optimization-framework-article-series.html" title="ASP.NET Web Optimization Framework (Bundling &amp; Minification) Articles " /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/04/aspnet-web-optimization-framework-article-series.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0IHQ3w5cSp7ImA9WhBWEUo.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-4961046522654483136</id><published>2013-04-05T22:02:00.001+05:30</published><updated>2013-04-05T22:02:12.229+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-05T22:02:12.229+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Picture Post" /><title>[Picture] ASP.NET MVC: Flow between Model-View-Controller</title><content type="html">&lt;p&gt;Many times I'm asked this very basic question that how the &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;ASP.NET MVC&lt;/a&gt; application flows between Model-View-Controller. So here we will try to understand it with &lt;a href="http://www.dotnetexpertguide.com/search/label/Picture%20Post"&gt;Picture Post&lt;/a&gt;.&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-n_atH6DVGqQ/UV76sJQsF1I/AAAAAAAABYk/tvS4wFnbPWE/s1600/Model-View-Controller+Flows.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Flow between Model-View-Controller in ASP.NET MVC" border="0" src="http://3.bp.blogspot.com/-n_atH6DVGqQ/UV76sJQsF1I/AAAAAAAABYk/tvS4wFnbPWE/s1600/Model-View-Controller+Flows.png" title="Flow between Model-View-Controller in ASP.NET MVC" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;User requests URL&lt;/li&gt;
&lt;li&gt;Request is mapped to Controller('s Action Method)&lt;/li&gt;
&lt;li&gt;Action Method process Model and select View(Result Type)&lt;/li&gt;
&lt;li&gt;Processed Model is passed to View or Result Type&lt;/li&gt;
&lt;li&gt;Generated response sent back to user&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hope this would be helpful. Stay tuned for more post.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=fFl8pxub16Q:SC8rb6Jc2SY:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=fFl8pxub16Q:SC8rb6Jc2SY:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=fFl8pxub16Q:SC8rb6Jc2SY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=fFl8pxub16Q:SC8rb6Jc2SY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=fFl8pxub16Q:SC8rb6Jc2SY:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=fFl8pxub16Q:SC8rb6Jc2SY:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=fFl8pxub16Q:SC8rb6Jc2SY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=fFl8pxub16Q:SC8rb6Jc2SY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=fFl8pxub16Q:SC8rb6Jc2SY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/fFl8pxub16Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/4961046522654483136/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/04/aspnet-mvc-flow-between-model-view-controller.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/4961046522654483136?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/4961046522654483136?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/fFl8pxub16Q/aspnet-mvc-flow-between-model-view-controller.html" title="[Picture] ASP.NET MVC: Flow between Model-View-Controller" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-n_atH6DVGqQ/UV76sJQsF1I/AAAAAAAABYk/tvS4wFnbPWE/s72-c/Model-View-Controller+Flows.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/04/aspnet-mvc-flow-between-model-view-controller.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0cMRXc9fip7ImA9WhBQEE8.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-6136759877501192975</id><published>2013-03-12T00:41:00.000+05:30</published><updated>2013-03-12T00:41:24.966+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-03-12T00:41:24.966+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET 4.5" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Featured" /><title>ASP.NET 4.5 Model Binding: Creating Custom Value Provider</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-tVA1SCmrfrg/UT4moISIobI/AAAAAAAABYE/4wBQrId11a4/s1600/ASP.NET.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="150" src="http://4.bp.blogspot.com/-tVA1SCmrfrg/UT4moISIobI/AAAAAAAABYE/4wBQrId11a4/s200/ASP.NET.png" width="150" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;With ASP.NET 4.5, ASP.NET introduced model binding for web forms as well. Model binding helps to simplify code focused data access logic within web forms. Check out &lt;a href="http://www.asp.net/vnext/overview/aspnet-web-forms/aspnet-45-web-forms-model-binding" target="_blank"&gt;this video&lt;/a&gt; by Scott Hanselman to know more on ASP.NET 4.5 Web Forms Model Binding.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;Here in this post, we will see how we can create our own custom value provider (read &lt;a href="http://www.dotnetexpertguide.com/2013/01/aspnet-mvc-value-provider-for-encrypted-query-string.html"&gt;my post&lt;/a&gt; on how I used value provider for encrypted query string in MVC application). We will also examine inbuilt class of ASP.NET 4.5 model binding framework which can be useful in creating custom value provider more easily with focused approach.&lt;/p&gt;
&lt;p&gt;Before we look into actual interfaces and classes, let us examine few basics of model binding framework. All model binding framework and corresponding classes are resides in &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.modelbinding.aspx" target="_blank"&gt;System.Web.ModelBinding&lt;/a&gt; namespace which is newly introduced with ASP.NET 4.5. For any value provider to work with model binder it requires two components one is implementation of &lt;b&gt;value provider&lt;/b&gt; which reads data from request and forward it to model binder and other one is &lt;b&gt;value provider source attribute&lt;/b&gt; which expose the actual value provider instance.  Have a look at below code snippet here QueryStringAttribute is value provider source attribute which expose object of QueryStringValueProvider so model binder can use it to fetch data.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; IQueryable&amp;lt;Blog&amp;gt; SelectMethod([QueryString]&lt;span class="kwrd"&gt;int&lt;/span&gt;? id)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4&gt;Creating Value Provider Source Attribute&lt;/h4&gt;
&lt;p&gt;To create custom value provider attribute we can derive Attribute class and implement &lt;b&gt;IValueProviderSource&lt;/b&gt; interface as displayed in below code snippet. &lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomValueProviderAttribute : Attribute, IValueProviderSource&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; IValueProvider GetValueProvider(ModelBindingExecutionContext modelBindingExecutionContext)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; CustomValueProvider(modelBindingExecutionContext);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Here we can have access of &lt;b&gt;ModelBindingExecutionContext&lt;/b&gt; and we can pass same to value provider if it is required. Through ModelBindingExecutionContext we can also have access of &lt;b&gt;HttpContextBase&lt;/b&gt; and &lt;b&gt;ModelStateDictionary&lt;/b&gt;. &lt;/p&gt;
&lt;h4&gt;Creating Value Provider&lt;/h4&gt;
&lt;p&gt;Same way we can create Custom Value Provider by implementing &lt;b&gt;IValueProvider&lt;/b&gt; interface. Below code snippet shows pseudo code for the same.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomValueProvider : IValueProvider&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    ModelBindingExecutionContext _modelBindingExecutionContext;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; CustomValueProvider(ModelBindingExecutionContext modelBindingExecutionContext)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;._modelBindingExecutionContext = modelBindingExecutionContext;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; ContainsPrefix(&lt;span class="kwrd"&gt;string&lt;/span&gt; prefix)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="rem"&gt;// validate if requested key is exist or not&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; ValueProviderResult GetValue(&lt;span class="kwrd"&gt;string&lt;/span&gt; key)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="rem"&gt;// return ValueProviderResult object we &lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="rem"&gt;// can use ModelBindingExecutionContext&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="rem"&gt;// to access request data&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once we are ready we can use created value provider as &lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;SelectMethod([CustomValueProvider]&lt;span class="kwrd"&gt;int&lt;/span&gt;? id, [CustomValueProvider]&lt;span class="kwrd"&gt;string&lt;/span&gt; name)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;As noted earlier, there are few inbuilt classes in ASP.NET 4.5 model binding framework which give more focused control over custom business logic. Here we will also examine one of its which is &lt;b&gt;SimpleValueProvider&lt;/b&gt;. Here we will examine how we can focus on core logic and leaving other responsibility on core framework.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomValueProvider : SimpleValueProvider&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; CustomValueProvider(ModelBindingExecutionContext modelBindingExecutionContext)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(modelBindingExecutionContext)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; FetchValue(&lt;span class="kwrd"&gt;string&lt;/span&gt; key)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="rem"&gt;// here we can access this.ModelBindingExecutionContext&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="rem"&gt;// and can look into request data. Once we fetch requested&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="rem"&gt;// data we just need to return actual value for e.g.            &lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;"dotnetExpertGuide.com"&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="rem"&gt;// NOTE: WE ARE NOT RETURNING ValueProviderResult INSTANCE&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Earlier with IValueProvider, we had to check if requested key exist or not and if it is then instantiating ValueProviderResult and return it. While with SimpleValueProvider we only need to return actual value of requested key or null incase if it does not exist rest will be taken care by SimpleValueProvider class. Another such framework class is &lt;b&gt;NameValueCollectionValueProvider&lt;/b&gt; which act as a base class to create value provider from name value collection. Here I am not demonstrating it. I am leaving it for reader &lt;b&gt;:)&lt;/b&gt;.&lt;/p&gt;
&lt;h4&gt; SimpleValueProvider and ASP.NET MVC&lt;/h4&gt;
&lt;p&gt;Can’t we have/introduce SimpleValueProvider class for MVC in upcoming version?&lt;/p&gt;
&lt;h4&gt;ModelStateDictionary&lt;/h4&gt;
&lt;p&gt;Once model binding is done for parameter it is added to ModelStateDictionary dictionary along with its value. For e.g.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;SelectMethod([CustomValueProvider]&lt;span class="kwrd"&gt;int&lt;/span&gt;? id, [CustomValueProvider]&lt;span class="kwrd"&gt;string&lt;/span&gt; name)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In above code once model binding is done for parameter id, it is added to ModelStateDictionary and it is accessible in rest of the parameter model binding i.e. parameter name here.&lt;/p&gt;
&lt;p&gt;Hope this would be helpful. Stay tuned for more post.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Ip_UL69NIXg:4eFEEw1TApk:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=Ip_UL69NIXg:4eFEEw1TApk:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Ip_UL69NIXg:4eFEEw1TApk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Ip_UL69NIXg:4eFEEw1TApk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Ip_UL69NIXg:4eFEEw1TApk:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=Ip_UL69NIXg:4eFEEw1TApk:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Ip_UL69NIXg:4eFEEw1TApk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=Ip_UL69NIXg:4eFEEw1TApk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=Ip_UL69NIXg:4eFEEw1TApk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/Ip_UL69NIXg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/6136759877501192975/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/03/aspnet-45-model-binding-creating-custom-value-provider.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/6136759877501192975?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/6136759877501192975?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/Ip_UL69NIXg/aspnet-45-model-binding-creating-custom-value-provider.html" title="ASP.NET 4.5 Model Binding: Creating Custom Value Provider" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-tVA1SCmrfrg/UT4moISIobI/AAAAAAAABYE/4wBQrId11a4/s72-c/ASP.NET.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/03/aspnet-45-model-binding-creating-custom-value-provider.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEYCQXs6fyp7ImA9WhBREEs.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-55033939258264194</id><published>2013-02-28T20:58:00.000+05:30</published><updated>2013-02-28T21:12:40.517+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-02-28T21:12:40.517+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Picture Post" /><title>[Picture] ASP.NET MVC: Action Filter Life Cycle</title><content type="html">&lt;p&gt;
It is said that &lt;b&gt;A picture is worth a thousand words&lt;/b&gt;, so this time I come up with Picture Post to discuss action filter life cycle in ASP.NET MVC. Hope reader would like it. So do share it and stay connected for more post on Action Filter.
&lt;/p&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-HTqI6Xlmd68/US9yhFT1ZYI/AAAAAAAABXc/3GH4hFjLCik/s1600/action+filter+life+cycle.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img alt="ASP.NET MVC: Action Filter Life Cycle" border="0" src="http://4.bp.blogspot.com/-HTqI6Xlmd68/US9yhFT1ZYI/AAAAAAAABXc/3GH4hFjLCik/s1600/action+filter+life+cycle.png" title="ASP.NET MVC: Action Filter Life Cycle" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;font-size: 20px;"&gt;ASP.NET MVC: Action Filter Life Cycle&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=BSWORQNlHfM:PwkSvNXdVSk:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=BSWORQNlHfM:PwkSvNXdVSk:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=BSWORQNlHfM:PwkSvNXdVSk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=BSWORQNlHfM:PwkSvNXdVSk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=BSWORQNlHfM:PwkSvNXdVSk:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=BSWORQNlHfM:PwkSvNXdVSk:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=BSWORQNlHfM:PwkSvNXdVSk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=BSWORQNlHfM:PwkSvNXdVSk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=BSWORQNlHfM:PwkSvNXdVSk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/BSWORQNlHfM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/55033939258264194/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/02/aspnet-mvc-action-filter-life-cycle.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/55033939258264194?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/55033939258264194?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/BSWORQNlHfM/aspnet-mvc-action-filter-life-cycle.html" title="[Picture] ASP.NET MVC: Action Filter Life Cycle" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-HTqI6Xlmd68/US9yhFT1ZYI/AAAAAAAABXc/3GH4hFjLCik/s72-c/action+filter+life+cycle.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/02/aspnet-mvc-action-filter-life-cycle.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0MAQXYzcCp7ImA9WhBTGUg.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-8343234949219603252</id><published>2013-02-15T23:32:00.000+05:30</published><updated>2013-02-15T23:34:00.888+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-02-15T23:34:00.888+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PowerShell" /><title>PowerShell: Accessing static member in PowerShell Script</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-TVJesIgJoIc/UR50zTxJhwI/AAAAAAAABWc/-Hww47khc1E/s1600/powershell+logo.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-TVJesIgJoIc/UR50zTxJhwI/AAAAAAAABWc/-Hww47khc1E/s200/powershell+logo.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Recently I created &lt;a target="_blank" href="https://nuget.org/packages/UpgradeMvc3ToMvc4"&gt;NuGet package&lt;/a&gt; which &lt;a href="http://www.dotnetexpertguide.com/2013/02/aspnet-mvc-auto-upgrade-mvc-3-to-mvc-4-application.html"&gt;auto upgrade ASP.NET MVC 3 application to MVC 4&lt;/a&gt; and while I was creating this package I worked with powershell. Before that I never worked with powershell so I learned a few thing so thought to share it with reader. If you are new to powershell then you can execute powershell script with command prompt or if you are GUI inclined then Windows 7 also have PowerShell ISE (Integrated Scripting Environment).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;To open command prompt type &lt;b&gt;powershell in Run window&lt;/b&gt; and press enter or search for powershell in Start all programs and open powershell ISE.&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-COkNltoYpWM/UR51PKj3uWI/AAAAAAAABWk/H82QdFd9UKY/s1600/PowerShell+ISE.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-COkNltoYpWM/UR51PKj3uWI/AAAAAAAABWk/H82QdFd9UKY/s1600/PowerShell+ISE.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;In PowerShell ISE we can see two pane Command Pane &amp; Output Pane. Both pane names are self explanatory so I'm leaving it upto you ;) But yes in command window we can fire any command which we can fire in Windows Command Prompt.&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-6VhuSP8iacM/UR51axlTmqI/AAAAAAAABW0/NC6qxL9QQW4/s1600/PowerShell+ISE+pane.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="285" src="http://1.bp.blogspot.com/-6VhuSP8iacM/UR51axlTmqI/AAAAAAAABW0/NC6qxL9QQW4/s400/PowerShell+ISE+pane.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h4&gt;Accessing Static Member&lt;/h4&gt;
&lt;p&gt;Sometime we need to access static member from powershell script as I required it while creating &lt;a href="http://www.dotnetexpertguide.com/2013/02/aspnet-mvc-auto-upgrade-mvc-3-to-mvc-4-application.html"&gt;this NuGet package&lt;/a&gt;. So in powershell, we can access static member with &lt;b&gt;Scope Resolution Operator (::)&lt;/b&gt;. For e.g. type following command in powershell command pane&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-3NM2a2pmsmE/UR51ZH-iBFI/AAAAAAAABWs/cXmMpj9TAdc/s1600/Static+member+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-3NM2a2pmsmE/UR51ZH-iBFI/AAAAAAAABWs/cXmMpj9TAdc/s1600/Static+member+1.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Upon hitting enter in command prompt we can see output in output pane&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-mJHE4uXNdak/UR51bAattNI/AAAAAAAABW4/UfV_-xI3Xc0/s1600/Static+member.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-mJHE4uXNdak/UR51bAattNI/AAAAAAAABW4/UfV_-xI3Xc0/s1600/Static+member.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;So in powershell we can access static member with the help of &lt;b&gt;Scope Resolution Operator (::)&lt;/b&gt;. Hope this would be helpful!&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TjyTfctS-Nw:WQwODtnBzdU:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=TjyTfctS-Nw:WQwODtnBzdU:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TjyTfctS-Nw:WQwODtnBzdU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TjyTfctS-Nw:WQwODtnBzdU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TjyTfctS-Nw:WQwODtnBzdU:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=TjyTfctS-Nw:WQwODtnBzdU:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TjyTfctS-Nw:WQwODtnBzdU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TjyTfctS-Nw:WQwODtnBzdU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=TjyTfctS-Nw:WQwODtnBzdU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/TjyTfctS-Nw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/8343234949219603252/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/02/powershell-accessing-static-member-in-powershell-script.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/8343234949219603252?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/8343234949219603252?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/TjyTfctS-Nw/powershell-accessing-static-member-in-powershell-script.html" title="PowerShell: Accessing static member in PowerShell Script" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-TVJesIgJoIc/UR50zTxJhwI/AAAAAAAABWc/-Hww47khc1E/s72-c/powershell+logo.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/02/powershell-accessing-static-member-in-powershell-script.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU4GQHc5cCp7ImA9WhBXFkg.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-7048472109820484647</id><published>2013-02-03T23:10:00.000+05:30</published><updated>2013-03-30T21:08:41.928+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-03-30T21:08:41.928+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="MVC 4" /><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><title>ASP.NET MVC: Auto upgrade MVC 3 to MVC 4 application</title><content type="html">&lt;p&gt;Yeah you read it right... Its NuGet package to upgrade existing ASP.NET MVC 3 application to ASP.NET MVC 4 application. From last month or two, I was planning to create NuGet package which automatically upgrade existing MVC 3 application to MVC 4 application but somehow I was keeping it at lower priority, but during last week I observed that many readers are redirected to &lt;a href="http://www.dotnetexpertguide.com/2011/12/upgrade-aspnet-mvc-3-project-to-mvc-4.html"&gt;Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4&lt;/a&gt; from this &lt;a target="_blank" href="http://stackoverflow.com/questions/12655808/asp-net-mvc3-to-mvc4-upgrade-tool"&gt;stackoverflow question&lt;/a&gt; and I found that developer community are also looking for tool which automatically handle this upgrade. So I have created NuGet package and published it here &lt;a href="https://nuget.org/packages/UpgradeMvc3ToMvc4" target="_blank"&gt;https://nuget.org/packages/UpgradeMvc3ToMvc4&lt;/a&gt; and whole exported package is uploaded here &lt;a href="https://github.com/NandipMakwana/UpgradeMvc3ToMvc4" target="_blank"&gt;https://github.com/NandipMakwana/UpgradeMvc3ToMvc4&lt;/a&gt;&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-A_yS2CTmqpg/UQ6WIRiEj0I/AAAAAAAABVA/IS8deD7V9m4/s1600/Upgrade.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-A_yS2CTmqpg/UQ6WIRiEj0I/AAAAAAAABVA/IS8deD7V9m4/s200/Upgrade.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-0GTm3Taujl0/UQ6j3__CMGI/AAAAAAAABVY/_VImNPCd79I/s1600/upgrade.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" width="600" src="http://2.bp.blogspot.com/-0GTm3Taujl0/UQ6j3__CMGI/AAAAAAAABVY/_VImNPCd79I/s400/upgrade.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;I have upgraded few MVC 3 application to MVC 4 application with this package and it worked fine for me. &lt;b&gt;If solution is under source control then please make sure that all web.config are writable and checked out.&lt;/b&gt; Along with upgradtion I have also included &lt;a target="_blank" href="http://blogs.msdn.com/b/rickandy/archive/2012/09/17/asp-net-mvc-4-mobile-caching-bug-fixed.aspx"&gt;MVC 4 FixedDisplayModes&lt;/a&gt;, &lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-45-mvc-4-revisiting-IBundleTransform-in-bundling.html"&gt;Web Optimization Framework&lt;/a&gt;, DotNetOpenAuth packages for enabling &lt;a href="http://www.dotnetexpertguide.com/2012/08/facebook-twitter-oauth-openid-login-with-aspnet-mvc-4-application.html"&gt;oAuth login&lt;/a&gt; after upgrade. It will also add AuthConfig.cs &amp; BundleConfig.cs in App_Start directory. To enable oAuth &amp; Bundling, we need to add following line in Application_Start in global.asax.cs.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;BundleConfig.RegisterBundles(BundleTable.Bundles);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;AuthConfig.RegisterAuth();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once we upgrade with this package, Visual Studio will ask to reload project as we are changing project type from MVC 3 to MVC 4.&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-f-L0F7Mfjjo/UQ6YU2TdffI/AAAAAAAABVM/J2dg88m4pqk/s1600/project%2Breload.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="115" width="400" src="http://1.bp.blogspot.com/-f-L0F7Mfjjo/UQ6YU2TdffI/AAAAAAAABVM/J2dg88m4pqk/s400/project%2Breload.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h4&gt;How to test upgrade is success or not?&lt;/h4&gt;
&lt;p&gt;Yes... here is quick tip. Copy any view let say &lt;b&gt;Index.cshtml&lt;/b&gt; and copy it and rename it to &lt;b&gt;Index.mobile.cshtml&lt;/b&gt;. Now browse upgraded MVC 4 application with mobile simulator or override user agent in browser.&lt;/p&gt;
&lt;p&gt;Hope It will be helpful and do let me know your feedback here in comment.&lt;/p&gt;
&lt;p&gt;Project URL: &lt;a target="_blank" href="https://github.com/NandipMakwana/UpgradeMvc3ToMvc4"&gt;https://github.com/NandipMakwana/UpgradeMvc3ToMvc4&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet URL: &lt;a target="_blank" href="https://nuget.org/packages/UpgradeMvc3ToMvc4"&gt;https://nuget.org/packages/UpgradeMvc3ToMvc4&lt;/a&gt;&lt;/p&gt;
&lt;p class="updated-text"&gt;&lt;a href="https://twitter.com/NandipMakwana/status/301362923916386304" target="_blank"&gt;One of the reader&lt;/a&gt; run in error &lt;b&gt;Could not load file or assembly 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.&lt;/b&gt; solution to this error is answered on this &lt;a href="http://stackoverflow.com/questions/9431975/could-not-load-file-or-assembly-system-net-http-version-2-0-0-0-in-mvc4-web-ap#10249823" target="_blank"&gt;Stack Overflow question&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bdPDEnRA9oI:w8XHyTTsBZU:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=bdPDEnRA9oI:w8XHyTTsBZU:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bdPDEnRA9oI:w8XHyTTsBZU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bdPDEnRA9oI:w8XHyTTsBZU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bdPDEnRA9oI:w8XHyTTsBZU:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=bdPDEnRA9oI:w8XHyTTsBZU:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bdPDEnRA9oI:w8XHyTTsBZU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bdPDEnRA9oI:w8XHyTTsBZU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=bdPDEnRA9oI:w8XHyTTsBZU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/bdPDEnRA9oI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/7048472109820484647/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/02/aspnet-mvc-auto-upgrade-mvc-3-to-mvc-4-application.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/7048472109820484647?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/7048472109820484647?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/bdPDEnRA9oI/aspnet-mvc-auto-upgrade-mvc-3-to-mvc-4-application.html" title="ASP.NET MVC: Auto upgrade MVC 3 to MVC 4 application" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-A_yS2CTmqpg/UQ6WIRiEj0I/AAAAAAAABVA/IS8deD7V9m4/s72-c/Upgrade.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/02/aspnet-mvc-auto-upgrade-mvc-3-to-mvc-4-application.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUBQH0zfip7ImA9WhNbF00.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-5268536428894433303</id><published>2013-01-20T19:11:00.000+05:30</published><updated>2013-01-20T23:54:11.386+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-01-20T23:54:11.386+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: Order of view selection</title><content type="html">&lt;p&gt;Few days ago, I and one of my friends were discussing basic of &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;ASP.NET MVC&lt;/a&gt;. After some discussion we came on point in which order views are selected. Because there can be more than one view with same name. For e.g. we can have &lt;b&gt;index.aspx, index.ascx, index.cshtml, index.vbhtml and all this can be in controller specific folder as well shared folder&lt;/b&gt;. So in which order view is getting selected? Which view has higher priority? So to getting it clearly, quickly I changed action method to return view which does not exists as mentioned below.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Index()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="str"&gt;"NotExists"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;We built application and run it and it throw an exception &lt;b&gt;The view 'NotExists' or its master was not found or no view engine supports the searched locations. &lt;u&gt;The following locations were searched:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-XL96_ktyq_Y/UPvxJ1K3X-I/AAAAAAAABUg/_u9w-7cN00Q/s1600/Order%2Bof%2Bview%2Bselection.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-XL96_ktyq_Y/UPvxJ1K3X-I/AAAAAAAABUg/_u9w-7cN00Q/s1600/Order%2Bof%2Bview%2Bselection.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;"A picture is worth a thousand words" Based on above exception and image we can conclude following order of view selection.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;View/[CONTROLLER]/[VIEW].aspx&lt;/li&gt;
&lt;li&gt;View/[CONTROLLER]/[VIEW].ascx&lt;/li&gt;
&lt;li&gt;View/Shared/[VIEW].aspx&lt;/li&gt;
&lt;li&gt;View/Shared/[VIEW].ascx&lt;/li&gt;
&lt;li&gt;View/[CONTROLLER]/[VIEW].cshtml&lt;/li&gt;
&lt;li&gt;View/[CONTROLLER]/[VIEW].vbhtml&lt;/li&gt;
&lt;li&gt;View/Shared/[VIEW].cshtml&lt;/li&gt;
&lt;li&gt;View/Shared/[VIEW].vbhtml&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So hope this quick post would be helpful to understand order of view selection in ASP.NET MVC. Stay tuned to upcoming post to know how we can change this order of view selection and how it could hit &lt;a href="http://www.dotnetexpertguide.com/search/label/Performance"&gt;performance&lt;/a&gt; gain.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=nVqD0GLBr0w:O_eWK2VUrvs:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=nVqD0GLBr0w:O_eWK2VUrvs:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=nVqD0GLBr0w:O_eWK2VUrvs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=nVqD0GLBr0w:O_eWK2VUrvs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=nVqD0GLBr0w:O_eWK2VUrvs:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=nVqD0GLBr0w:O_eWK2VUrvs:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=nVqD0GLBr0w:O_eWK2VUrvs:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=nVqD0GLBr0w:O_eWK2VUrvs:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=nVqD0GLBr0w:O_eWK2VUrvs:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/nVqD0GLBr0w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/5268536428894433303/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/01/aspnet-mvc-order-of-view-selection.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/5268536428894433303?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/5268536428894433303?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/nVqD0GLBr0w/aspnet-mvc-order-of-view-selection.html" title="ASP.NET MVC: Order of view selection" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-XL96_ktyq_Y/UPvxJ1K3X-I/AAAAAAAABUg/_u9w-7cN00Q/s72-c/Order%2Bof%2Bview%2Bselection.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/01/aspnet-mvc-order-of-view-selection.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEINSXkyeSp7ImA9WhNbFks.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-1746184140306369734</id><published>2013-01-18T19:00:00.000+05:30</published><updated>2013-01-20T12:53:18.791+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-01-20T12:53:18.791+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio" /><title>ASP.NET: JavaScript Source Maps with Microsoft Ajax Minifier</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-_rlleTuodNA/UNXc5XYO3xI/AAAAAAAABNA/TzyNfNuLeZM/s1600/ASP.NET.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="150" src="http://3.bp.blogspot.com/-_rlleTuodNA/UNXc5XYO3xI/AAAAAAAABNA/TzyNfNuLeZM/s200/ASP.NET.png" width="150" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;3 days back jQuery announced &lt;a target="_blank" href="http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/"&gt;release of jQuery 1.9&lt;/a&gt;. One of the great things with this release is that it is shipped with &lt;a target="_blank" href="http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/"&gt;Source Maps&lt;/a&gt;. However in general there are very rare scenarios where we require to debug jQuery but still this would be really helpful to vast community specially contributor. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;Now as a being web developer (more specific &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; developer), first question arise is that how do I generate JavaScript source map for my custom component or JavaScript library in visual studio and &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; application? So here in this post we will see how to configure &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; web application to generate minified version of JavaScript and JavaScript source map at build time.&lt;/p&gt;
&lt;p&gt;To get started, download &amp; install &lt;a target="_blank" href="http://ajaxmin.codeplex.com/"&gt;Microsoft Ajax Minifier&lt;/a&gt;. Microsoft Ajax Minifier enables us to minify JavaScript and CSS. It also included Visual Studio build task so we can minify JavaScript and CSS at build time. Microsoft Ajax Minifier also supports &lt;a target="_blank" href="http://ajaxmin.codeplex.com/wikipage?title=SourceMaps"&gt;source map generation&lt;/a&gt;. Naming convention for source map is &lt;b&gt;output-min-filename.map&lt;/b&gt;. &lt;/p&gt;
&lt;p&gt;So to see it in action follow the below quick step and get sample ready! &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create web application project&lt;/li&gt;
&lt;li&gt;Add your JavaScript component file to project&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-o0cK5rmmri0/UPk7TUltZaI/AAAAAAAABTk/CBCkVT6J4H4/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-o0cK5rmmri0/UPk7TUltZaI/AAAAAAAABTk/CBCkVT6J4H4/s1600/1.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Open &lt;b&gt;.csproj&lt;/b&gt; file in editor and add build task as mentioned below&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-Vw66NcAErTU/UPk7T74RfCI/AAAAAAAABTw/4AK_EaH2fSk/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-Vw66NcAErTU/UPk7T74RfCI/AAAAAAAABTw/4AK_EaH2fSk/s1600/2.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Now build project and open windows explorer and navigate where JavaScript file is located. Here we can see generated minified file along with source map&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-V91UNGgE-wI/UPk7UXfZi9I/AAAAAAAABT8/r1sUxoTyqTE/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-V91UNGgE-wI/UPk7UXfZi9I/AAAAAAAABT8/r1sUxoTyqTE/s1600/3.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;So this was all about how we can generate JavaScript source map in ASP.NET application with Microsoft Ajax Minifier build task. &lt;/p&gt;
 &lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bZ3ZfqpaZmU:-pA4Xtp0VEI:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=bZ3ZfqpaZmU:-pA4Xtp0VEI:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bZ3ZfqpaZmU:-pA4Xtp0VEI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bZ3ZfqpaZmU:-pA4Xtp0VEI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bZ3ZfqpaZmU:-pA4Xtp0VEI:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=bZ3ZfqpaZmU:-pA4Xtp0VEI:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bZ3ZfqpaZmU:-pA4Xtp0VEI:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=bZ3ZfqpaZmU:-pA4Xtp0VEI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=bZ3ZfqpaZmU:-pA4Xtp0VEI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/bZ3ZfqpaZmU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/1746184140306369734/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/01/aspnet-javascript-source-maps-with-microsoft-ajax-minifier.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/1746184140306369734?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/1746184140306369734?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/bZ3ZfqpaZmU/aspnet-javascript-source-maps-with-microsoft-ajax-minifier.html" title="ASP.NET: JavaScript Source Maps with Microsoft Ajax Minifier" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-_rlleTuodNA/UNXc5XYO3xI/AAAAAAAABNA/TzyNfNuLeZM/s72-c/ASP.NET.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/01/aspnet-javascript-source-maps-with-microsoft-ajax-minifier.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8CR3k9cCp7ImA9WhNUFEw.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-3713819480766312217</id><published>2013-01-06T01:33:00.000+05:30</published><updated>2013-01-06T01:44:26.768+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-01-06T01:44:26.768+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Cryptography" /><category scheme="http://www.blogger.com/atom/ns#" term="Security" /><category scheme="http://www.blogger.com/atom/ns#" term="C#.NET" /><title>C#: String [Dictionary] encryption with cryptography</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-pGqtz3iBQdM/UOfmcmHUTbI/AAAAAAAABRA/LNW3Hl1QlBQ/s1600/encryption.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-pGqtz3iBQdM/UOfmcmHUTbI/AAAAAAAABRA/LNW3Hl1QlBQ/s1600/encryption.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;In last post, we have seen &lt;a href="http://www.dotnetexpertguide.com/2013/01/aspnet-mvc-value-provider-for-encrypted-query-string.html"&gt;how we can leverage ASP.NET MVC framework extensibility to handle encrypted query string&lt;/a&gt;. After reading that post one reader asked how to encrypt/decrypt query string (i.e. dictionary) in ASP.NET. We had &lt;a href="http://www.dotnetexpertguide.com/2013/01/aspnet-mvc-value-provider-for-encrypted-query-string.html#comment-755683633"&gt;some discussion on post comment&lt;/a&gt; and found that after encrypting query string user run in another error "The request filtering module is configured to deny a request that contains a double escape sequence" while using encrypted string as route value. So I thought to write post on string encryption/decryption which discuss precautions before using it as part of URL. However I cant post actual implementation here but we will look in other solution. (I am not much sound in cryptography still we will try to learn together &lt;b&gt;:)&lt;/b&gt;.)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;h4&gt;Encryption, Cryptography &amp; string&lt;/h4&gt;
&lt;p&gt;All cryptographic operation is done on byte and not on string so we need to create byte array from string. And in case of encrypted query string, we need to create string from query string dictionary and I recommend to apply some cryptography operation on string rather than just applying plus/minus or similar operation on character.&lt;/p&gt;
&lt;h4&gt;String Encryption&lt;/h4&gt;
&lt;p&gt;So here we will try to understand string encryption with code snippet.&lt;/p&gt;
&lt;h4&gt;1. Create string from dictionary&lt;/h4&gt;
&lt;p&gt;Following code snippet show how to create string from dictionary.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
&lt;div id="codeSnippet" class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; StringFromDictionary(Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; dictionary)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;.Join(&lt;span class="str"&gt;"-"&lt;/span&gt;, dictionary.Select(d =&amp;gt; d.Key + &lt;span class="str"&gt;"+"&lt;/span&gt; + d.Value));&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4&gt;2. Convert string in byte array&lt;/h4&gt;
&lt;p&gt;As we noted earlier, all cryptographic operation are done on byte and not on string so we need to create byte array from string.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
&lt;div id="codeSnippet" class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] queryString = Encoding.UTF8.GetBytes(StringFromDictionary(dictionary));&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4&gt;3. Apply encryption on byte array&lt;/h4&gt;
&lt;p&gt;Now we have byte array ready so we can apply cryptographic operation on it. For this post we are using .NET framework &lt;a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx" target="_blank"&gt;RijndaelManaged&lt;/a&gt; class.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="rem"&gt;// Change keyBytes or generate based on some logic&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="rem"&gt;// We are using IV (Initialization Vector) same as keyBytes &lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&lt;span class="rem"&gt;// but strongly recommend to change or generate separate one&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] keyBytes = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[16] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;RijndaelManaged rijndaelManaged = &lt;span class="kwrd"&gt;new&lt;/span&gt; RijndaelManaged&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    Mode = CipherMode.CBC,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    Padding = PaddingMode.PKCS7,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    KeySize = 128,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    BlockSize = 128,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    Key = keyBytes,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    IV = keyBytes&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;};&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Here we have initialized RijndaelManaged instance and now we can use it for encryption and decryption. &lt;b&gt;For demonstrate purpose, I am using same IV (Initialization Vector) as private key but it is strongly recommend to generate separate one&lt;/b&gt;.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] EncryptBytes(&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] bytes)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; rijndaelManaged.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And we can retrieve encrypted byte as&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] encryptedBytes = EncryptBytes(queryString);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4&gt;4. Convert encrypted byte array in Base64 string&lt;/h4&gt;
&lt;p&gt;Now we have encrypted byte array and we need to convert it in string, but as it is encrypted byte array we are converting it in Base64 format.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToBase64(&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] bytes)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; strBase64;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    strBase64 = Convert.ToBase64String(bytes);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; strBase64.Replace(&lt;span class="str"&gt;'+'&lt;/span&gt;, &lt;span class="str"&gt;'-'&lt;/span&gt;).Replace(&lt;span class="str"&gt;'/'&lt;/span&gt;, &lt;span class="str"&gt;'_'&lt;/span&gt;).Replace(&lt;span class="str"&gt;'='&lt;/span&gt;, &lt;span class="str"&gt;','&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;After converting it in Base64 we are replacing &lt;b&gt;+/=&lt;/b&gt; with &lt;b&gt;-_,&lt;/b&gt; because &lt;b&gt;+/=&lt;/b&gt; is the only symbol which is part of &lt;a href="http://en.wikipedia.org/wiki/Base64#Examples" target="_blank"&gt;Base64 character set&lt;/a&gt; and it could change the meaning of URL or it could return in error "The request filtering module is configured to deny a request that contains a double escape sequence". So we are replacing it with &lt;b&gt;-_,&lt;/b&gt; and before decryption we will replace it back to &lt;b&gt;+/=&lt;/b&gt;.&lt;/p&gt;
&lt;h4&gt;String Decryption&lt;/h4&gt; 
&lt;p&gt;Decryption step is simply reverse of above. Let’s have a quick view of it.&lt;/p&gt;
&lt;h4&gt;1. Convert encrypted Base64 string in byte array&lt;/h4&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] FromBase64(&lt;span class="kwrd"&gt;string&lt;/span&gt; encryptedText)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    encryptedText = encryptedText.Replace(&lt;span class="str"&gt;'-'&lt;/span&gt;, &lt;span class="str"&gt;'+'&lt;/span&gt;).Replace(&lt;span class="str"&gt;'_'&lt;/span&gt;, &lt;span class="str"&gt;'/'&lt;/span&gt;).Replace(&lt;span class="str"&gt;','&lt;/span&gt;, &lt;span class="str"&gt;'='&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.FromBase64String(encryptedText);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] encryptedBytes = FromBase64(encryptedString);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4&gt;2. Apply decryption on byte array&lt;/h4&gt;
&lt;p&gt;Once we have encrypted byte array back we can decrypt it with RijndaelManaged.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] DecryptBytes(&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] bytes)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; rijndaelManaged.CreateDecryptor().TransformFinalBlock(bytes, 0, bytes.Length);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] decryptedBytes = DecryptBytes(encryptedBytes);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4&gt;3. Populated dictionary from decrypted bytes&lt;/h4&gt;
&lt;p&gt;Now we can populate dictionary back from decrypted byte array as explained below.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; DictionaryFromBytes(&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] bytes)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; decryptedString = Encoding.UTF8.GetString(bytes);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; dictionary = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt;[] keyValuePair = decryptedString.Split(&lt;span class="str"&gt;'-'&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; key &lt;span class="kwrd"&gt;in&lt;/span&gt; keyValuePair)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;string&lt;/span&gt;[] keyValue = key.Split(&lt;span class="str"&gt;'+'&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        dictionary.Add(keyValue[0], keyValue[1]);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; dictionary;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4&gt;Conclusion&lt;/h4&gt;
&lt;p&gt;Here we have discussed how to encrypt string with cryptographic operation and what are the required precautions while using Base64 encoded string in URL. Along with this don’t forget to &lt;a href="http://www.dotnetexpertguide.com/2013/01/aspnet-mvc-value-provider-for-encrypted-query-string.html"&gt;read how to implement encrypted query string in ASP.NET MVC application with lesser code&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=M8u_qTe4po4:Q7pgaS-Zrhk:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=M8u_qTe4po4:Q7pgaS-Zrhk:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=M8u_qTe4po4:Q7pgaS-Zrhk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=M8u_qTe4po4:Q7pgaS-Zrhk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=M8u_qTe4po4:Q7pgaS-Zrhk:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=M8u_qTe4po4:Q7pgaS-Zrhk:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=M8u_qTe4po4:Q7pgaS-Zrhk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=M8u_qTe4po4:Q7pgaS-Zrhk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=M8u_qTe4po4:Q7pgaS-Zrhk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/M8u_qTe4po4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/3713819480766312217/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/01/csharp-string-dictionary-encryption-with-cryptography.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/3713819480766312217?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/3713819480766312217?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/M8u_qTe4po4/csharp-string-dictionary-encryption-with-cryptography.html" title="C#: String [Dictionary] encryption with cryptography" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-pGqtz3iBQdM/UOfmcmHUTbI/AAAAAAAABRA/LNW3Hl1QlBQ/s72-c/encryption.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/01/csharp-string-dictionary-encryption-with-cryptography.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8HR3c9eip7ImA9WhNUFEw.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-3864258761641266739</id><published>2013-01-01T14:58:00.000+05:30</published><updated>2013-01-06T01:43:56.962+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-01-06T01:43:56.962+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Featured" /><title>ASP.NET MVC Value Provider for encrypted query string</title><content type="html">&lt;p&gt;By looking at the post title, it is quite clear that we are about to discuss, query string encryption in ASP.NET MVC application. But I am more interested in demonstrating extensibility of ASP.NET MVC framework and how we can leverage it by plugging our custom logic into ASP.NET MVC life cycle.&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-e6I8CyF7AG4/UOKfFIZfoyI/AAAAAAAABNs/2L68gGJhvrg/s1600/asp.net%2Bmvc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-e6I8CyF7AG4/UOKfFIZfoyI/AAAAAAAABNs/2L68gGJhvrg/s200/asp.net%2Bmvc.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://www.dotnetexpertguide.com/search/label/Featured"&gt;As always let me start with scratch&lt;/a&gt;, recently I came across a &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;ASP.NET MVC&lt;/a&gt; application, where several action method were accepting query string parameter and later we identified that few of them must accept encrypted query string parameter. Along with this I also wanted to make sure that&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;We don’t want to decrypt query string manually in each action method&lt;/b&gt; as there are numerous number of action method were already implanted and it could be increase in further development.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Model binding must not break due to this encryption&lt;/b&gt; because application was running well without encryption and all code was done accordingly.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Once action method start accepting encrypted query string it must not accept plain query string. i.e. without encryption.&lt;/b&gt; For e.g. earlier http://localhost/Invoice/ViewInvoice?invoiceid=123 after encryption it could be http://localhost/Invoice/ViewInvoice/ENCRYPTED-QUERY-STRING now it must not serve http://localhost/Invoice/ViewInvoice?invoiceid=123 (this could be possible due to default Value Provider)&lt;/li&gt;
&lt;li&gt;In one sentence, &lt;b&gt;I don’t want to change anything in action method implementation not even decryption nor change in action parameter&lt;/b&gt; and model binding must take care of this decryption wherever applicable (read &lt;b&gt;only wherever applicable&lt;/b&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So I created one Value Provider which handle this decryption logic. For those who don’t know what is Value Provider in ASP.NET MVC.&lt;/p&gt;
&lt;p class="updated-text"&gt;In one sentence, Value Provider feeds data to model binder.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Mvc;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CryptoValueProvider : IValueProvider&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; ContainsPrefix(&lt;span class="kwrd"&gt;string&lt;/span&gt; prefix)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; ValueProviderResult GetValue(&lt;span class="kwrd"&gt;string&lt;/span&gt; key)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CryptoValueProviderFactory : ValueProviderFactory&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; IValueProvider GetValueProvider(ControllerContext controllerContext)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; CryptoValueProvider();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And registered this value provider in global.asax.cs as follow.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Application_Start()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    ValueProviderFactories.Factories.Insert(0, &lt;span class="kwrd"&gt;new&lt;/span&gt; CryptoValueProviderFactory());&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Here we added CryptoValueProvide at 0&lt;sup&gt;th&lt;/sup&gt; index because we wanted to give it utmost priority and it started working as we expected model binder took place after decrypting (if it is encrypted) query string. &lt;b&gt;Everything was agreed except point 3 mentioned above.&lt;/b&gt; Because now whenever user enter http://localhost/Invoice/ViewInvoice?invoiceid=123 manually at that time CryptoValueProvider does not find valid encrypted query string hence model binder passes model binding request to next ValueProvider i.e. &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.querystringvalueprovider(v=vs.108).aspx" target="_blank"&gt;System.Web.Mvc.QueryStringValueProvider&lt;/a&gt; (there are total 5 default value provider) and it found valid query string parameter and model binder took place! As per the point 3, this must not allow.&lt;/p&gt;
&lt;p&gt;In this case, we need to ensure that for encrypted query string, there must be only one ValueProvider and that is CryptoValueProvider and default value provider must not act in the case of encrypted query string. &lt;b&gt;In other word, we need to change (and not add/insert in) value provider collection run time instead registering it globally via global.asax.cs.&lt;/b&gt; &lt;/p&gt;
&lt;p&gt;Again this is the point where you should be aware with ASP.NET MVC life cycle to decide where to alter value provider collection. Covering complete life cycle is beyond the scope of this post. I will try to cover in upcoming post but for this post we only require to know that &lt;b&gt;model binding take place after authorization&lt;/b&gt;. So we created CryptoValueProviderAttribute &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;action filter&lt;/a&gt; which implements IAuthorizationFilter interface and here in this action filter we can alter value provider collection and we can decorate respective action method (which require encrypted query string) with this attribute. So now with combination of CryptoValueProvider and CryptoValueProviderAttribute we can ensure that the only CryptoValueProvider (and not default 5 value provider) will act in case of encrypted query string and vice-versa.&lt;/p&gt;
&lt;h4&gt;Conclusion&lt;/h4&gt;
&lt;p&gt;The goal of this post is to demonstrate robust extensibility feature of ASP.NET MVC framework with which we can implement our custom logic out of the box way (Yes of course with lesser code and ease of maintainability). Hope this would be helpful. Comments are welcome and stay connected on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Crypto class which handle encryption and decryption&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Crypto&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Encrypt(Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; keyValue)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="rem"&gt;// encrypt query string key value pair&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; Decrypt(&lt;span class="kwrd"&gt;string&lt;/span&gt; encryptedText)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="rem"&gt;// decrypt encrypted query string into key value pair&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class="updated-text"&gt;
&lt;b&gt;Update&lt;/b&gt;&lt;br/&gt;
For detailed post on how to encrypt/decrypt string/dictionary &lt;a href="http://www.dotnetexpertguide.com/2013/01/csharp-string-dictionary-encryption-with-cryptography.html"&gt;read this post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;CryptoValueProvider&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CryptoValueProvider : IValueProvider&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    RouteData routeData = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; dictionary = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; CryptoValueProvider(RouteData routeData)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.routeData = routeData;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; ContainsPrefix(&lt;span class="kwrd"&gt;string&lt;/span&gt; prefix)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.routeData.Values[&lt;span class="str"&gt;"id"&lt;/span&gt;] == &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.dictionary = Crypto.Decrypt(&lt;span class="kwrd"&gt;this&lt;/span&gt;.routeData.Values[&lt;span class="str"&gt;"id"&lt;/span&gt;].ToString());&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.dictionary.ContainsKey(prefix.ToUpper());&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; ValueProviderResult GetValue(&lt;span class="kwrd"&gt;string&lt;/span&gt; key)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        ValueProviderResult result;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        result = &lt;span class="kwrd"&gt;new&lt;/span&gt; ValueProviderResult(&lt;span class="kwrd"&gt;this&lt;/span&gt;.dictionary[key.ToUpper()], &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.dictionary[key.ToUpper()], CultureInfo.CurrentCulture);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; result;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;CryptoValueProviderAttribute&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CryptoValueProviderAttribute : FilterAttribute, IAuthorizationFilter&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnAuthorization(AuthorizationContext filterContext)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        filterContext.Controller.ValueProvider = &lt;span class="kwrd"&gt;new&lt;/span&gt; CryptoValueProvider(filterContext.RouteData);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Usage&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[CryptoValueProvider]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult ViewInvoice(&lt;span class="kwrd"&gt;int&lt;/span&gt; invoiceid)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=sluBCGsLkcY:Jd0OcwoAvgs:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=sluBCGsLkcY:Jd0OcwoAvgs:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=sluBCGsLkcY:Jd0OcwoAvgs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=sluBCGsLkcY:Jd0OcwoAvgs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=sluBCGsLkcY:Jd0OcwoAvgs:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=sluBCGsLkcY:Jd0OcwoAvgs:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=sluBCGsLkcY:Jd0OcwoAvgs:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=sluBCGsLkcY:Jd0OcwoAvgs:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=sluBCGsLkcY:Jd0OcwoAvgs:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/sluBCGsLkcY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/3864258761641266739/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2013/01/aspnet-mvc-value-provider-for-encrypted-query-string.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/3864258761641266739?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/3864258761641266739?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/sluBCGsLkcY/aspnet-mvc-value-provider-for-encrypted-query-string.html" title="ASP.NET MVC Value Provider for encrypted query string" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-e6I8CyF7AG4/UOKfFIZfoyI/AAAAAAAABNs/2L68gGJhvrg/s72-c/asp.net%2Bmvc.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2013/01/aspnet-mvc-value-provider-for-encrypted-query-string.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkMER3wzfSp7ImA9WhBUF04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-4657419535136876549</id><published>2012-12-22T21:59:00.000+05:30</published><updated>2013-05-05T12:50:06.285+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T12:50:06.285+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: Accessing base controller from view</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-_rlleTuodNA/UNXc5XYO3xI/AAAAAAAABNA/TzyNfNuLeZM/s1600/ASP.NET.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-_rlleTuodNA/UNXc5XYO3xI/AAAAAAAABNA/TzyNfNuLeZM/s1600/ASP.NET.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Today, I was examining one ASP.NET MVC application for code optimization. And at the same time as a part of code rearrangement, I required to access base controller instance from view. So here in this post we will see how we can access base controller instance from within view. Before looking at actual implementation, let me describe how all controller were arranged.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;h4&gt;Controller structure&lt;/h4&gt;
&lt;p&gt;In MVC application, we had one controller named &lt;b&gt;BaseController&lt;/b&gt; derived from &lt;b&gt;System.Web.Mvc.Controller&lt;/b&gt; and all other application controller were derived from this &lt;b&gt;BaseController&lt;/b&gt; so we can have &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Hooking"&gt;hook&lt;/a&gt; in case if we require to plug some logic or extend all controller at later time. Following is pseudo code for the same.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BaseController : Controller&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _userRole;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; UserRole&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _userRole; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeController : BaseController&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Index()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In above pseudo code, for illustrative purpose we have put one property which expose role of logged in user. From within controller, we can access it with &lt;b&gt;this.UserRole&lt;/b&gt; but we cannot access it directly from view. &lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-GprB8Q4Ldd0/UNXc6uL_ImI/AAAAAAAABNM/b0I-B2V2giM/s1600/aspnet-mvc-ViewContext.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-GprB8Q4Ldd0/UNXc6uL_ImI/AAAAAAAABNM/b0I-B2V2giM/s1600/aspnet-mvc-ViewContext.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;As we can see in above image that we can access &lt;b&gt;ControllerBase&lt;/b&gt; with &lt;b&gt;@ViewContext.Controller&lt;/b&gt; but we can’t access our base controller directly. However we can cast &lt;b&gt;@ViewContext.Controller&lt;/b&gt; in &lt;b&gt;BaseController&lt;/b&gt; because our &lt;b&gt;BaseController&lt;/b&gt; is inherited from &lt;b&gt;System.Web.Mvc.Controller&lt;/b&gt; which is again inherited from &lt;b&gt;ControllerBase&lt;/b&gt; class. But each time casting &lt;b&gt;@ViewContext.Controller&lt;/b&gt; is not good way better we create extension method which cast it and return &lt;b&gt;BaseController&lt;/b&gt; instance. So below is the code which adds extension method to &lt;b&gt;ViewContext&lt;/b&gt; class.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ViewContextExtension&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; BaseController BaseController(&lt;span class="kwrd"&gt;this&lt;/span&gt; ViewContext view)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        BaseController baseController = (BaseController)view.Controller;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; baseController;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once we add above code we can access base controller with &lt;b&gt;@ViewContext.BaseController()&lt;/b&gt; and hence we can also access &lt;b&gt;@ViewContext.BaseController().UserRole&lt;/b&gt; and all other member of base controller from view. Hope this would be hopeful!&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=YyY4ytETqrw:QLOJmAC1m98:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=YyY4ytETqrw:QLOJmAC1m98:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=YyY4ytETqrw:QLOJmAC1m98:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=YyY4ytETqrw:QLOJmAC1m98:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=YyY4ytETqrw:QLOJmAC1m98:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=YyY4ytETqrw:QLOJmAC1m98:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=YyY4ytETqrw:QLOJmAC1m98:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=YyY4ytETqrw:QLOJmAC1m98:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=YyY4ytETqrw:QLOJmAC1m98:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/YyY4ytETqrw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/4657419535136876549/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-accessing-base-controller.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/4657419535136876549?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/4657419535136876549?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/YyY4ytETqrw/aspnet-mvc-accessing-base-controller.html" title="ASP.NET MVC: Accessing base controller from view" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-_rlleTuodNA/UNXc5XYO3xI/AAAAAAAABNA/TzyNfNuLeZM/s72-c/ASP.NET.png" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-accessing-base-controller.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkcDQn47cCp7ImA9WhBUF04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-7198999144343390149</id><published>2012-12-11T16:00:00.000+05:30</published><updated>2013-05-05T12:44:33.008+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T12:44:33.008+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: AllowAnonymous action filter</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-x4lyRCdLBZo/UMamZsmpqgI/AAAAAAAABGU/k3ydW00y1Ms/s1600/AllowAnonymous.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="ASP.NET MVC: AllowAnonymous" border="0" src="http://4.bp.blogspot.com/-x4lyRCdLBZo/UMamZsmpqgI/AAAAAAAABGU/k3ydW00y1Ms/s1600/AllowAnonymous.png" title="ASP.NET MVC: AllowAnonymous" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;AllowAnonymous attribute is used to skip authorization enforced by &lt;a href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-authorize-action-filter.html"&gt;Authorize attribute&lt;/a&gt;. Action method marked with AllowAnonymous will be always accessible by all users including anonymous users.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Attribute Usage:&lt;/b&gt; Controller &amp; method&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[AllowAnonymous]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Login()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Check out &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;ASP.NET MVC: Action filter series&lt;/a&gt; post to read about other available  action filters.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=XPQYfUEJ-9Y:06GadvsMZek:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=XPQYfUEJ-9Y:06GadvsMZek:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=XPQYfUEJ-9Y:06GadvsMZek:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=XPQYfUEJ-9Y:06GadvsMZek:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=XPQYfUEJ-9Y:06GadvsMZek:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=XPQYfUEJ-9Y:06GadvsMZek:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=XPQYfUEJ-9Y:06GadvsMZek:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=XPQYfUEJ-9Y:06GadvsMZek:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=XPQYfUEJ-9Y:06GadvsMZek:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/XPQYfUEJ-9Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/7198999144343390149/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-allowanonymous-action-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/7198999144343390149?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/7198999144343390149?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/XPQYfUEJ-9Y/aspnet-mvc-allowanonymous-action-filter.html" title="ASP.NET MVC: AllowAnonymous action filter" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-x4lyRCdLBZo/UMamZsmpqgI/AAAAAAAABGU/k3ydW00y1Ms/s72-c/AllowAnonymous.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-allowanonymous-action-filter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkcFR3Y5fCp7ImA9WhBUF04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-1195092241299758546</id><published>2012-12-11T10:00:00.000+05:30</published><updated>2013-05-05T12:43:36.824+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T12:43:36.824+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: Authorize action filter</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-aiXJs-bGe-Y/UMQXb7qnVxI/AAAAAAAABEo/autV-Abak6c/s1600/Authorize.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="ASP.NET MVC: Authorize" border="0" src="http://1.bp.blogspot.com/-aiXJs-bGe-Y/UMQXb7qnVxI/AAAAAAAABEo/autV-Abak6c/s1600/Authorize.png" title="ASP.NET MVC: Authorize" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Authorize attribute is used to restrict the access of action method based on role or logged in username. We have to supply comma separated list of user name or role with this attribute name. If user is not logged in then it will redirect it to login page.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Attribute Usage:&lt;/b&gt; Controller &amp; method&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[Authorize(Roles = &lt;span class="str"&gt;"Admin,Manager"&lt;/span&gt;)]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Report()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In above example, action method can be access by only users of Admin or Manager Role.&lt;/p&gt;
&lt;p&gt;Likewise we can also pass comma separated name of users as displayed below.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[Authorize(Users=&lt;span class="str"&gt;"Nandip,Makwana"&lt;/span&gt;)]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Report()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Check out &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;ASP.NET MVC: Action filter series&lt;/a&gt; post to read about other available  action filters.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=10cwm3JahaY:tZH-CV4493k:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=10cwm3JahaY:tZH-CV4493k:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=10cwm3JahaY:tZH-CV4493k:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=10cwm3JahaY:tZH-CV4493k:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=10cwm3JahaY:tZH-CV4493k:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=10cwm3JahaY:tZH-CV4493k:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=10cwm3JahaY:tZH-CV4493k:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=10cwm3JahaY:tZH-CV4493k:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=10cwm3JahaY:tZH-CV4493k:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/10cwm3JahaY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/1195092241299758546/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-authorize-action-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/1195092241299758546?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/1195092241299758546?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/10cwm3JahaY/aspnet-mvc-authorize-action-filter.html" title="ASP.NET MVC: Authorize action filter" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-aiXJs-bGe-Y/UMQXb7qnVxI/AAAAAAAABEo/autV-Abak6c/s72-c/Authorize.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-authorize-action-filter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEIHQXc9eSp7ImA9WhNWEU0.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-9102673275408918404</id><published>2012-12-10T07:58:00.000+05:30</published><updated>2012-12-10T07:58:50.961+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-12-10T07:58:50.961+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="IIS" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Featured" /><category scheme="http://www.blogger.com/atom/ns#" term="Performance" /><title>ASP.NET &amp; IIS: Domain/URL redirection best practice</title><content type="html">&lt;p&gt;In web application, many times we are redirecting domain to other (sub)domain or one url to another url within same domain. So here in this post we will discuss what are the best practices for domain redirection with respect to &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/2011/10/iis-7-tutorial-posts-link.html"&gt;IIS&lt;/a&gt; and what is the performance impact of it.&lt;/p&gt;
&lt;h4&gt;What are the scenarios for domain/url redirection?&lt;/h4&gt;
&lt;p&gt;Following two is the most common scenario for domain/url redirection.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;To enforce primary or canonical domain&lt;/b&gt; many time we want to redirect all request to either domain.com or www.domain.com i.e. with www or without www. Indeed this is also required for better SEO rank. You can read &lt;a href="http://www.dotnetexpertguide.com/2011/08/iis-7-redirect-domaincom-to.html"&gt;my post on same here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Change in URL&lt;/b&gt; sometime due to change in web url, we are redirecting one url (pattern) to another url (pattern).&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;What are the solutions?&lt;/h4&gt;
&lt;p&gt;Often many developers are handling this redirection at ASP.NET level i.e. through code with the help of &lt;b&gt;Response.Redirect, Response.RedirectPermanent, RedirectToAction, RedirectToRoute, etc.&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;As above all solutions are implemented through ASP.NET hence it initializes ASP.NET request processing and then after it redirect.&lt;/p&gt;
&lt;h4&gt;Is there any other BETTER solution?&lt;/h4&gt;
&lt;p&gt;As we know that web server (i.e. IIS in our case) receive request and then after IIS authenticate and identify requested resource type and accordingly it forward request to respective handler (ASP.NET, PHP, CGI, etc) to process it. So here is the scope that rather than handling it at ASP.NET level through code, we can also handle this redirection at IIS level far before forwarding request to respective handler. We can use &lt;a href="http://www.dotnetexpertguide.com/2011/08/iis-7-redirect-domaincom-to.html"&gt;URL Rewrite extension with IIS&lt;/a&gt; to implement domain/url redirection. URL Rewrite module is native IIS module and it plug into the request processing pipeline.&lt;/p&gt;
&lt;h4&gt;What is the BEST solution and how it could help to gain performance?&lt;/h4&gt;
&lt;p&gt;We have seen that we can handle such redirection at IIS level and code level through ASP.NET. So now it’s time to evaluate which one is best and how it could help us to gain little performance (yeah every micro-second counts when it come to performance). Have a look at below picture which shows IIS request processing life cycle and it also show where URL Rewrite module &amp; other handlers fit in IIS request processing pipeline. &lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-3oxRslK5VlI/UMVCoh0iP7I/AAAAAAAABF0/mVgpcCPYwx8/s1600/asp.net%2Bmvc%2Biis%2Bdomain%2Bredirect.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" title="IIS request processing lifecycle" alt="IIS request processing lifecycle" src="http://4.bp.blogspot.com/-3oxRslK5VlI/UMVCoh0iP7I/AAAAAAAABF0/mVgpcCPYwx8/s1600/asp.net%2Bmvc%2Biis%2Bdomain%2Bredirect.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;As we can see in above image that URL Rewrite module plugs far early (&lt;b&gt;A&lt;/b&gt; in image) into IIS request processing pipeline than other scripting handler (&lt;b&gt;B&lt;/b&gt; in image). Based on above image we can conclude as following.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If we implement redirection through code i.e. ASP.NET then it will redirect almost at the end of IIS request processing cycle hence new redirected request processing are delayed for time taken by Begin Request to Execute Handler (&lt;b&gt;A&lt;/b&gt; to &lt;b&gt;B&lt;/b&gt; in above image).&lt;/li&gt;
&lt;li&gt;And if we implement redirection with URL Rewrite module then it redirect in far early stage of IIS request processing cycle and hence new redirected request processing also starts in early stage.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So conclusion is that if we use URL Rewrite module than request are redirected in far early stage of request processing lifecycle and hence it could helps to gain better performance comparatively.&lt;/p&gt;
&lt;p&gt;Hope this would be helpful! You can read &lt;a href="http://www.dotnetexpertguide.com/search/label/Performance"&gt;other post on performance improvements here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=LuR16Z-LLU0:UyBy2K3nLas:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=LuR16Z-LLU0:UyBy2K3nLas:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=LuR16Z-LLU0:UyBy2K3nLas:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=LuR16Z-LLU0:UyBy2K3nLas:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=LuR16Z-LLU0:UyBy2K3nLas:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=LuR16Z-LLU0:UyBy2K3nLas:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=LuR16Z-LLU0:UyBy2K3nLas:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=LuR16Z-LLU0:UyBy2K3nLas:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=LuR16Z-LLU0:UyBy2K3nLas:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/LuR16Z-LLU0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/9102673275408918404/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/12/aspnet-iis-domain-url-redirection-best-practice.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/9102673275408918404?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/9102673275408918404?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/LuR16Z-LLU0/aspnet-iis-domain-url-redirection-best-practice.html" title="ASP.NET &amp; IIS: Domain/URL redirection best practice" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-3oxRslK5VlI/UMVCoh0iP7I/AAAAAAAABF0/mVgpcCPYwx8/s72-c/asp.net%2Bmvc%2Biis%2Bdomain%2Bredirect.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/12/aspnet-iis-domain-url-redirection-best-practice.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8NRHw8eSp7ImA9WhBUF04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-8249751967231149258</id><published>2012-12-09T10:00:00.000+05:30</published><updated>2013-05-05T12:41:35.271+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T12:41:35.271+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: OutputCache action filter</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-RZubUekE8ms/UMQXbIRvQzI/AAAAAAAABEQ/Dt-SUgfBteI/s1600/OutputCache.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="ASP.NET MVC: OutputCache" border="0" src="http://2.bp.blogspot.com/-RZubUekE8ms/UMQXbIRvQzI/AAAAAAAABEQ/Dt-SUgfBteI/s1600/OutputCache.png" title="ASP.NET MVC: OutputCache" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;OutputCache action filter attribute is used to control the output cache of action method result. We can also apply this attribute at controller level, once we apply this attribute at controller level, all action method result will be cached. Once action result are cached any subsequent request will be served from cache instead of processing it again.&lt;/p&gt;
&lt;div style="clear: both;"&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Attribute Usage:&lt;/b&gt; Controller &amp;amp; method&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[OutputCache(Duration=60)]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult About()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    ViewBag.date = DateTime.Now.ToString();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In above example, action method result will be cached for 60 seconds. Right usage of OutputCache attribute can help us to boost ASP.NET MVC application performance.&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-aAF1WpC2ylA/UMSXlewHceI/AAAAAAAABFU/InXYRufoqBc/s1600/OutputCache.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-aAF1WpC2ylA/UMSXlewHceI/AAAAAAAABFU/InXYRufoqBc/s1
600/OutputCache.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Apart from Duration, we can cache action result based on following criteria.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CacheProfile&lt;/li&gt;
&lt;li&gt;Duration&lt;/li&gt;
&lt;li&gt;Location&lt;/li&gt;
&lt;li&gt;NoStore&lt;/li&gt;
&lt;li&gt;SqlDependency&lt;/li&gt;
&lt;li&gt;VaryByContentEncoding&lt;/li&gt;
&lt;li&gt;VaryByCustom&lt;/li&gt;
&lt;li&gt;VaryByHeader&lt;/li&gt;
&lt;li&gt;VaryByParam&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Check out &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;ASP.NET MVC: Action filter series&lt;/a&gt; post to read about other available action filters.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp;amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=PbBKQyVsjDU:WjQ0wcivbqw:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=PbBKQyVsjDU:WjQ0wcivbqw:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=PbBKQyVsjDU:WjQ0wcivbqw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=PbBKQyVsjDU:WjQ0wcivbqw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=PbBKQyVsjDU:WjQ0wcivbqw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=PbBKQyVsjDU:WjQ0wcivbqw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=PbBKQyVsjDU:WjQ0wcivbqw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=PbBKQyVsjDU:WjQ0wcivbqw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=PbBKQyVsjDU:WjQ0wcivbqw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/PbBKQyVsjDU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/8249751967231149258/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-outputcache-action-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/8249751967231149258?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/8249751967231149258?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/PbBKQyVsjDU/aspnet-mvc-outputcache-action-filter.html" title="ASP.NET MVC: OutputCache action filter" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-RZubUekE8ms/UMQXbIRvQzI/AAAAAAAABEQ/Dt-SUgfBteI/s72-c/OutputCache.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-outputcache-action-filter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8GQnc7eyp7ImA9WhBUF04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-3526501977062204772</id><published>2012-12-08T10:00:00.000+05:30</published><updated>2013-05-05T12:40:23.903+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T12:40:23.903+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: SessionState action filter</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-pp3S_QKNb78/UMQXbf6ydYI/AAAAAAAABEc/CBYFkKfISOc/s1600/SessionState.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="ASP.NET MVC: SessionState" border="0" src="http://2.bp.blogspot.com/-pp3S_QKNb78/UMQXbf6ydYI/AAAAAAAABEc/CBYFkKfISOc/s1600/SessionState.png" title="ASP.NET MVC: SessionState" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;SessionState attributes specify the session state behavior for the controller. We can use this attribute only with controller. Sometime we require that we want to disable session state for specific controller, in this case we can apply SessionState attribute in ASP.NET MVC controller. &lt;b&gt;Please note that this attribute control the session state behavior for the specific controller and not session state mode for entire application.&lt;/b&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Attribute Usage:&lt;/b&gt; Controller&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[SessionState(System.Web.SessionState.SessionStateBehavior.Disabled)]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeController : Controller&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult About()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        Session[&lt;span class="str"&gt;"key"&lt;/span&gt;] = &lt;span class="str"&gt;"value"&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In the above example we have disabled session state for Home controller so now whenever we try to access session from within any action method of this controller, then it will throw an &lt;b&gt;Object reference not found exception&lt;/b&gt;. Following are list of session state behavior with this attribute.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Default&lt;/li&gt;
&lt;li&gt;Required&lt;/li&gt;
&lt;li&gt;ReadOnly&lt;/li&gt;
&lt;li&gt;Disabled&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Check out &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;ASP.NET MVC: Action filter series&lt;/a&gt; post to read about other available  action filters.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=KBVc4ZeRvAA:N8qwiFxyWbg:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=KBVc4ZeRvAA:N8qwiFxyWbg:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=KBVc4ZeRvAA:N8qwiFxyWbg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=KBVc4ZeRvAA:N8qwiFxyWbg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=KBVc4ZeRvAA:N8qwiFxyWbg:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=KBVc4ZeRvAA:N8qwiFxyWbg:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=KBVc4ZeRvAA:N8qwiFxyWbg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=KBVc4ZeRvAA:N8qwiFxyWbg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=KBVc4ZeRvAA:N8qwiFxyWbg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/KBVc4ZeRvAA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/3526501977062204772/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-sessionstate-action-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/3526501977062204772?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/3526501977062204772?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/KBVc4ZeRvAA/aspnet-mvc-sessionstate-action-filter.html" title="ASP.NET MVC: SessionState action filter" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-pp3S_QKNb78/UMQXbf6ydYI/AAAAAAAABEc/CBYFkKfISOc/s72-c/SessionState.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-sessionstate-action-filter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUACQXw9eyp7ImA9WhBUF04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-4254041434109833281</id><published>2012-12-07T10:00:00.000+05:30</published><updated>2013-05-05T12:39:20.263+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T12:39:20.263+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: ValidateInput action filter</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-kTm35iEeJ5k/UMQXajxq-oI/AAAAAAAABEE/Zw6IhhizHAE/s1600/ValidateInput.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="ASP.NET MVC: ValidateInput" border="0" src="http://3.bp.blogspot.com/-kTm35iEeJ5k/UMQXajxq-oI/AAAAAAAABEE/Zw6IhhizHAE/s1600/ValidateInput.png" title="ASP.NET MVC: ValidateInput" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;In ASP.NET MVC, by default all user posted data (i.e. query string params, form element, etc.) are validated for any potential dangerous content (i.e. HTML tag or script) to avoid XSS attacks. But sometime we need to accept such HTML content from user. For e.g. for blog application developed in MVC must allow publisher to post HTML content or sometime we allow user to post HTML comment etc. In such scenario we can use ValidateInput action filter to allow user to post HTML content and to bypass request validation for specific action method.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Attribute Usage:&lt;/b&gt; Controller &amp; method&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[ValidateInput(&lt;span class="kwrd"&gt;false&lt;/span&gt;)]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult PostComment(&lt;span class="kwrd"&gt;string&lt;/span&gt; comment)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once we apply ValidateInput with false as displayed in above code snippet, request validation will not fire for this action method. &lt;b&gt;But in such scenario we must ensure that we apply our custom logic to avoid any malicious user input.&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Check out &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;ASP.NET MVC: Action filter series&lt;/a&gt; post to read about other available  action filters.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TeOUQKihv8Y:7j5NUTZhAYw:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=TeOUQKihv8Y:7j5NUTZhAYw:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TeOUQKihv8Y:7j5NUTZhAYw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TeOUQKihv8Y:7j5NUTZhAYw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TeOUQKihv8Y:7j5NUTZhAYw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=TeOUQKihv8Y:7j5NUTZhAYw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TeOUQKihv8Y:7j5NUTZhAYw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=TeOUQKihv8Y:7j5NUTZhAYw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=TeOUQKihv8Y:7j5NUTZhAYw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/TeOUQKihv8Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/4254041434109833281/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-validateinput-action-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/4254041434109833281?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/4254041434109833281?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/TeOUQKihv8Y/aspnet-mvc-validateinput-action-filter.html" title="ASP.NET MVC: ValidateInput action filter" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-kTm35iEeJ5k/UMQXajxq-oI/AAAAAAAABEE/Zw6IhhizHAE/s72-c/ValidateInput.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-validateinput-action-filter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUIMRH8zfSp7ImA9WhBUF0g.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-6691488631114243000</id><published>2012-11-24T11:26:00.000+05:30</published><updated>2013-05-05T17:03:05.185+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T17:03:05.185+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Featured" /><title>ASP.NET web optimization framework with MVC 3 &amp; ASP.NET 4.0 web form</title><content type="html">&lt;p&gt;Yesterday, I came across a &lt;a target="_blank" href="http://forums.asp.net/t/1860759.aspx/1?Error+System+Web+Http+namespace+not+defined"&gt;forum post&lt;/a&gt;, where user was facing problem in integrating &lt;a target="_blank" href="http://aspnetoptimization.codeplex.com/"&gt;web optimization framework&lt;/a&gt; with MVC 3. So here in this post we will see how we can integrate asp.net web optimization framework with MVC 3 and ASP.NET 4.0 web form application.&lt;/p&gt;
&lt;p&gt;Web optimization framework was introduced with MVC 4 and it is included in default MVC 4 template. But we can use it with MVC 3 and ASP.NET 4.0 web form application as well. This is because web optimization framework is built on top of framework 4.0. So here are the steps to use web optimization framework with ASP.NET 4.0 application.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create new ASP.NET 4.0 web form or MVC 3 application&lt;/li&gt;
&lt;li&gt;Add web optimization package by issuing following command in Visual studio package manager console&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-rCWyQLkHh0A/ULBd1mNzYaI/AAAAAAAABBc/NsatBfUwoTQ/s1600/aspnet%2Bweb%2Boptimization.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="58" src="http://4.bp.blogspot.com/-rCWyQLkHh0A/ULBd1mNzYaI/AAAAAAAABBc/NsatBfUwoTQ/s640/aspnet%2Bweb%2Boptimization.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Now add following code in global.asax.cs&lt;/li&gt;
&lt;/ul&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Optimization;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Application_Start()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    Bundle commonBundle = &lt;span class="kwrd"&gt;new&lt;/span&gt; ScriptBundle(&lt;span class="str"&gt;"~/bundle/common"&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        .Include(&lt;span class="str"&gt;"~/scripts/common.js"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    BundleTable.Bundles.Add(commonBundle);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Now build and browse &lt;b&gt;~/bundle/common&lt;/b&gt; and we can see minified version of JavaScript. So this is how we can see default bundle in action with ASP.NET 4.0 and MVC 3 application. You can refer my following post on advanced concept in web optimization framework.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-45-mvc-4-revisiting-IBundleTransform-in-bundling.html"&gt;ASP.NET 4.5 &amp; MVC 4:  Revisiting IBundleTransform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-45-mvc-4-bundling-next-approach.html"&gt;ASP.NET 4.5 &amp; MVC 4 Bundling: Next Approach&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-bundling-auto-sync-javascript-model-with-mvc-model.html"&gt;ASP.NET MVC Bundling: Auto sync JavaScript model with MVC model&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Check out this index post on &lt;a href="http://www.dotnetexpertguide.com/2013/04/aspnet-web-optimization-framework-article-series.html"&gt;ASP.NET Web Optimization Framework (a.k.a Bundling &amp; Minification)&lt;/a&gt; to read other post on same.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=W786k0MypXw:PIQM9aLVjQw:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=W786k0MypXw:PIQM9aLVjQw:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=W786k0MypXw:PIQM9aLVjQw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=W786k0MypXw:PIQM9aLVjQw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=W786k0MypXw:PIQM9aLVjQw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=W786k0MypXw:PIQM9aLVjQw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=W786k0MypXw:PIQM9aLVjQw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=W786k0MypXw:PIQM9aLVjQw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=W786k0MypXw:PIQM9aLVjQw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/W786k0MypXw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/6691488631114243000/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/11/aspnet-web-optimization-framework-with-mvc3-aspnet-40-web-forms.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/6691488631114243000?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/6691488631114243000?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/W786k0MypXw/aspnet-web-optimization-framework-with-mvc3-aspnet-40-web-forms.html" title="ASP.NET web optimization framework with MVC 3 &amp; ASP.NET 4.0 web form" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-rCWyQLkHh0A/ULBd1mNzYaI/AAAAAAAABBc/NsatBfUwoTQ/s72-c/aspnet%2Bweb%2Boptimization.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/11/aspnet-web-optimization-framework-with-mvc3-aspnet-40-web-forms.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8MR344fip7ImA9WhBbEkg.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-9102452207323337882</id><published>2012-11-22T22:54:00.000+05:30</published><updated>2013-05-11T12:01:26.036+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-11T12:01:26.036+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: Action filter series</title><content type="html">&lt;p&gt;Over the last few days, I was getting many requests from reader and friends, to start beginner level article series on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; and &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;. Generally I am sharing &lt;a href="http://www.dotnetexpertguide.com/search/label/Featured"&gt;my learning experience&lt;/a&gt; here on this blog and mostly which fall in &lt;a href="http://www.dotnetexpertguide.com/search/label/Featured"&gt;intermediate or advanced level&lt;/a&gt;. So I thought to write several beginners level article series on ASP.NET MVC. Towards to this step, this is the first article series on action filter in ASP.NET MVC. In this series we will see different available action filter in MVC including MVC 4. Do request other article series here with me; I will try my best to get it here. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httppost-action-filter.html"&gt; ASP.NET MVC: HttpPost action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-requirehttps-action-filter.html"&gt; ASP.NET MVC: RequireHttps action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-nonaction-action-filter.html"&gt; ASP.NET MVC: NonAction action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httpget-action-filter.html"&gt; ASP.NET MVC: HttpGet action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httpdelete-action-filter.html"&gt; ASP.NET MVC: HttpDelete action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httpput-action-filter.html"&gt; ASP.NET MVC: HttpPut action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-actionname-action-filter_24.html"&gt; ASP.NET MVC: ActionName action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httphead-action-filter.html"&gt; ASP.NET MVC: HttpHead action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httpoptions-action-filter.html"&gt; ASP.NET MVC: HttpOptions action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httppatch-action-filter.html"&gt; ASP.NET MVC: HttpPatch action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-acceptverbs-action-filter.html"&gt; ASP.NET MVC: AcceptVerbs action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-childactiononly-action-filter.html"&gt; ASP.NET MVC: ChildActionOnly action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-validateinput-action-filter.html"&gt;ASP.NET MVC: ValidateInput action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-sessionstate-action-filter.html"&gt;ASP.NET MVC: SessionState action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-outputcache-action-filter.html"&gt;ASP.NET MVC: OutputCache action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-authorize-action-filter.html"&gt;ASP.NET MVC: Authorize action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2012/12/aspnet-mvc-allowanonymous-action-filter.html"&gt;ASP.NET MVC: AllowAnonymous action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/2013/05/aspnet-mvc-handleerror-action-filter.html"&gt;ASP.NET MVC: HandleError action filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;ASP.NET MVC: ValidateAntiForgeryToken action filter&lt;/li&gt;
&lt;li&gt;ASP.NET MVC: AsyncTimeout action filter&lt;/li&gt;
&lt;li&gt;ASP.NET MVC: NoAsyncTimeout action filter&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hope this would be helpful!&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=GmMd-B_lqOg:Qm_9q1ke7ZU:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=GmMd-B_lqOg:Qm_9q1ke7ZU:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=GmMd-B_lqOg:Qm_9q1ke7ZU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=GmMd-B_lqOg:Qm_9q1ke7ZU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=GmMd-B_lqOg:Qm_9q1ke7ZU:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=GmMd-B_lqOg:Qm_9q1ke7ZU:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=GmMd-B_lqOg:Qm_9q1ke7ZU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=GmMd-B_lqOg:Qm_9q1ke7ZU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=GmMd-B_lqOg:Qm_9q1ke7ZU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/GmMd-B_lqOg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/9102452207323337882/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/9102452207323337882?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/9102452207323337882?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/GmMd-B_lqOg/aspnet-mvc-action-filter-series.html" title="ASP.NET MVC: Action filter series" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUIARXo8cCp7ImA9WhBUF0g.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-5136724333310500719</id><published>2012-11-12T00:22:00.000+05:30</published><updated>2013-05-05T17:02:24.478+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T17:02:24.478+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="vNext" /><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="MVC 4" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Featured" /><category scheme="http://www.blogger.com/atom/ns#" term="Performance" /><title>ASP.NET MVC Bundling: Auto sync JavaScript model with MVC model</title><content type="html">&lt;p&gt;In yesterdays post &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-45-mvc-4-bundling-next-approach.html"&gt;ASP.NET 4.5 &amp; MVC 4 Bundling: Next Approach&lt;/a&gt;, we have seen how we can pass additional parameters to bundle transform so we can utilize it while generating bundle response. I suggest you to read that post first before starting with this post.&lt;/p&gt;
&lt;h4&gt;What was the original idea?&lt;/h4&gt;
&lt;p&gt;Recently in one application, I have to create one JavaScript object which represents C# enum in client side. Later on C# enum keep extending and at the same time I used to add entry in JavaScript object too. Everything was fine but sometime me or team member forget to sync JavaScript object with C# enum when adding or removing existing entry in C# enum and JavaScript starts breaking and further more each time syncing JavaScript object with C# enum was also tedious task specially when team member is new and do not know whole application architecture. So I though let me create one HTTP handler which generates dynamic JavaScript which represent C# enum. &lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-uUm0vhrZ8Jc/UJ6Rn4WOeiI/AAAAAAAAA_8/6u1jtAMtmpw/s1600/ASP.NET.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-uUm0vhrZ8Jc/UJ6Rn4WOeiI/AAAAAAAAA_8/6u1jtAMtmpw/s1600/ASP.NET.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Later when I started implementing HTTP handler, I realize that there are many other JavaScript that can be generated from other C# type and could save developer time &amp; headache especially from task such as syncing JavaScript object/class with C# type. Let me elaborate whole scenario. The application was in &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt; and for user friendliness &amp; performance point of view we all are using lots of AJAX &amp; JSON. For e.g.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt; application return list of item in JSON format via JSON result, and we bind it with UI&lt;/li&gt;
&lt;li&gt;Client post JSON object back to server and desterilize it back in &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt; model or model binder take care of it&lt;/li&gt;
&lt;li&gt;Some time we are using JavaScript MVVM library such as &lt;a href="http://www.dotnetexpertguide.com/search/label/knockout.js"&gt;knockout.js&lt;/a&gt; or sometime we are using library like &lt;a href="http://backbonejs.org/" target="_blank"&gt;backbone.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Microsoft also introduced &lt;a href="http://www.asp.net/single-page-application" target="_blank"&gt;Single Page Application (SPA)&lt;/a&gt; with set of JavaScript library&lt;/li&gt;
&lt;li&gt;And many other approaches with AJAX, JSON&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In short when you are creating rich application, model in client side (JavaScript) is also as important as server side MVC model, entity model or whatever approach you are using. And most of time JavaScript model is same as server side model. So now let back to main point… when I implemented HTTP handler, I thought let me generate JavaScript class for server side model too. So whenever any new property added or removed at that time it also syncs JavaScript class with it.&lt;/p&gt;
&lt;p&gt;Later in this post, we will also see how we can use this auto generated JavaScript model with JavaScript library like knockout.js and backbone.js&lt;/p&gt;
&lt;h4&gt;Why &amp; How I ended up with bundling in ASP.NET MVC application&lt;/h4&gt;
&lt;p&gt;I could implement it as HTTP handler and almost implemented but later I thought let me see if I could create custom bundle and transform for the same. There are few advantages of using bundling over HTTP handler while response are same application wide irrespective of user. It is&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It stores generated response in server cache hence it is faster than processing each and every request to HTTP handler (&lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-45-mvc-4-revisiting-IBundleTransform-in-bundling.html"&gt;read my full post on same here&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;We can configure bundle url something pretty like &lt;b&gt;~/bundle/jsmodel&lt;/b&gt; over &lt;b&gt;~/jsmodel.ashx&lt;/b&gt; (yeah we can configure route for the same but still…)&lt;/li&gt;
&lt;li&gt;We can clearly separate transformation logic in separate class/library etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Following is the full source code for the same staring with Bundle which accepts .NET type as an extra parameter.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; JSModelBundle : Bundle&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; List&amp;lt;Type&amp;gt; _modelList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;amp;lt;Type&amp;amp;gt;();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; JSModelBundle(&lt;span class="kwrd"&gt;string&lt;/span&gt; virtualPath)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(virtualPath, &lt;span class="kwrd"&gt;new&lt;/span&gt; JSModelTransform())&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; List&amp;lt;Type&amp;gt; ModelList&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _modelList; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        set { _modelList = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Transform type which transforms .NET type in JavaScript object/class.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; JSModelTransform : IBundleTransform&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Process(BundleContext context, BundleResponse response)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;string&lt;/span&gt; strResponse = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        response.ContentType = &lt;span class="str"&gt;"text/javascript"&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        JSModelBundle bundle = (context.BundleCollection&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            .Where(b =&amp;gt; b.Path == context.BundleVirtualPath)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;            .FirstOrDefault()) &lt;span class="kwrd"&gt;as&lt;/span&gt; JSModelBundle;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Type type &lt;span class="kwrd"&gt;in&lt;/span&gt; bundle.ModelList)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (type.IsClass)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;                strResponse += GetFunctionBodyForClass(type);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (type.IsEnum)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;                strResponse += GetObjectBodyForEnum(type);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        response.Content = strResponse;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; GetFunctionBodyForClass(Type type)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        StringBuilder sbFunctionBody = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        sbFunctionBody.AppendLine(&lt;span class="str"&gt;"function "&lt;/span&gt; + type.Name + &lt;span class="str"&gt;"() {"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (PropertyInfo p &lt;span class="kwrd"&gt;in&lt;/span&gt; type.GetProperties())&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;            sbFunctionBody.AppendLine(&lt;span class="str"&gt;"this."&lt;/span&gt; + p.Name + &lt;span class="str"&gt;" = '';"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        sbFunctionBody.Append(&lt;span class="str"&gt;"}"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        sbFunctionBody.Append(&lt;span class="str"&gt;"\n\n"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; sbFunctionBody.ToString();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; GetObjectBodyForEnum(Type type)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        StringBuilder sbFunctionBody = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        sbFunctionBody.AppendLine(type.Name + &lt;span class="str"&gt;" = {"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;int&lt;/span&gt; enumLength = type.GetEnumValues().Length;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;int&lt;/span&gt; index = 1;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var v &lt;span class="kwrd"&gt;in&lt;/span&gt; type.GetEnumValues())&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; strEnumField = v.ToString() + &lt;span class="str"&gt;" : "&lt;/span&gt; + (&lt;span class="kwrd"&gt;int&lt;/span&gt;)v;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (index &amp;amp;lt; enumLength)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;                strEnumField += &lt;span class="str"&gt;","&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            sbFunctionBody.AppendLine(strEnumField);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;            index++;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        sbFunctionBody.Append(&lt;span class="str"&gt;"}"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        sbFunctionBody.Append(&lt;span class="str"&gt;"\n\n"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; sbFunctionBody.ToString();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Sample .NET types&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Product&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; ProductId { get; set; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ProductCode { get; set; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ProductName { get; set; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;enum&lt;/span&gt; Event&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    Add,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    Update,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    Delete,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;and code snippet for how to include it in bundle&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;JSModelBundle bundle = &lt;span class="kwrd"&gt;new&lt;/span&gt; JSModelBundle(&lt;span class="str"&gt;"~/bundles/JsModel"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;bundle.ModelList.Add(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Product));&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;bundle.ModelList.Add(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Event));&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;bundles.Add(bundle);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-uwdEJgLVp7I/UJ_OBR0EmOI/AAAAAAAABBA/NlN3Y5D2li4/s1600/jsmodel.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-uwdEJgLVp7I/UJ_OBR0EmOI/AAAAAAAABBA/NlN3Y5D2li4/s1600/jsmodel.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Now we can use generated JavaScript model with backbone.js as displayed below.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;var product = &lt;span class="kwrd"&gt;new&lt;/span&gt; Backbone.Model(&lt;span class="kwrd"&gt;new&lt;/span&gt; Product());&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Following is the code snippet of using it with knockout.js&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;var product = &lt;span class="kwrd"&gt;new&lt;/span&gt; Product();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;ko.applyBindings(product);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Hope this would be helpful!&lt;/p&gt;
&lt;p&gt;Check out this index post on &lt;a href="http://www.dotnetexpertguide.com/2013/04/aspnet-web-optimization-framework-article-series.html"&gt;ASP.NET Web Optimization Framework (a.k.a Bundling &amp; Minification)&lt;/a&gt; to read other post on same.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=-Cc6AjD-aBI:NvmQsA9iw6Q:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=-Cc6AjD-aBI:NvmQsA9iw6Q:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=-Cc6AjD-aBI:NvmQsA9iw6Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=-Cc6AjD-aBI:NvmQsA9iw6Q:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=-Cc6AjD-aBI:NvmQsA9iw6Q:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=-Cc6AjD-aBI:NvmQsA9iw6Q:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=-Cc6AjD-aBI:NvmQsA9iw6Q:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=-Cc6AjD-aBI:NvmQsA9iw6Q:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=-Cc6AjD-aBI:NvmQsA9iw6Q:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/-Cc6AjD-aBI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/5136724333310500719/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-bundling-auto-sync-javascript-model-with-mvc-model.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/5136724333310500719?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/5136724333310500719?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/-Cc6AjD-aBI/aspnet-mvc-bundling-auto-sync-javascript-model-with-mvc-model.html" title="ASP.NET MVC Bundling: Auto sync JavaScript model with MVC model" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-uUm0vhrZ8Jc/UJ6Rn4WOeiI/AAAAAAAAA_8/6u1jtAMtmpw/s72-c/ASP.NET.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-bundling-auto-sync-javascript-model-with-mvc-model.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUMCSHc_cSp7ImA9WhBUF0g.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-6105398456408422051</id><published>2012-11-11T00:22:00.000+05:30</published><updated>2013-05-05T17:01:09.949+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T17:01:09.949+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="vNext" /><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET 4.5" /><category scheme="http://www.blogger.com/atom/ns#" term="MVC 4" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Featured" /><title>ASP.NET 4.5 &amp; MVC 4 Bundling: Next Approach</title><content type="html">&lt;p&gt;In the earlier post, we have seen &lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-45-mvc-4-revisiting-IBundleTransform-in-bundling.html"&gt;how we can access bundle context while processing bundle through custom transform&lt;/a&gt;. Taking it further, in this post we will see how we can utilize bundle context to pass extra parameters to transform and later how we can utilize those parameters to transform bundle.&lt;/p&gt;
&lt;h4&gt;What are the needs of extra parameter?&lt;/h4&gt;
&lt;p&gt;Since &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET%204.5"&gt;ASP.NET 4.5&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC%204"&gt;MVC 4&lt;/a&gt; developer preview version, bundling was introduced with two transforms JsMinify and CssMinify which minify JavaScript &amp; CSS respectively. Then after community came with few more transforms for Sass, LESS, CoffeeScript, (TypeScript might be in pipeline) etc. But if you have noticed, one thing is common in all these transforms is that all transforms are applying on files. We include some files in bundle with &lt;b&gt;Bundle.Include&lt;/b&gt; and those files are transformed. In other word, we could pass only file (or VirtualFile) to bundle transform and bundle transform read those file content and process it. But what if I want to pass other information to bundle transform? Let say I want to pass Dictionary collection to bundle transform. At first glance, we don’t have any mechanism for the same! Is it really so? Nop we can pass such extra parameter to bundle transform and can utilize it while generating bundle response. Following is the steps for the same.&lt;/p&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-uUm0vhrZ8Jc/UJ6Rn4WOeiI/AAAAAAAAA_8/6u1jtAMtmpw/s1600/ASP.NET.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-uUm0vhrZ8Jc/UJ6Rn4WOeiI/AAAAAAAAA_8/6u1jtAMtmpw/s1600/ASP.NET.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Create one class which is derived from &lt;b&gt;Bundle&lt;/b&gt; class and add properties for the any extra parameter in it as displayed below.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomBundle : Bundle&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; _metaInfo = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; CustomBundle(&lt;span class="kwrd"&gt;string&lt;/span&gt; virtualPath)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(virtualPath, &lt;span class="kwrd"&gt;new&lt;/span&gt; CustomTransform())&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; MetaInfo&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _metaInfo; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        set { _metaInfo = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For demonstration purpose, I have created one property of type dictionary but it could be of any type. With the help of this property, we will pass additional info to bundle transform.&lt;/p&gt;
&lt;p&gt;With custom bundle class we have defined list of additional parameters. Now following is the code of custom transform type and how we can read those extra parameters with the help of bundle context while generating response. For more info on &lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-45-mvc-4-revisiting-IBundleTransform-in-bundling.html"&gt;custom transform type read my previous post here&lt;/a&gt;.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomTransform : IBundleTransform&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Process(BundleContext context, BundleResponse response)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        CustomBundle bundle = (context.BundleCollection&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;            .Where(b =&amp;gt; b.Path == context.BundleVirtualPath)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;            .FirstOrDefault()) &lt;span class="kwrd"&gt;as&lt;/span&gt; CustomBundle;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;        response.Content = JsonConvert.SerializeObject(bundle.MetaInfo);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;As we know that we can have access of bundle collection while transforming bundle. So we are extracting current bundle from bundle collection and hence type of current bundle is CustomBundle we can access extra parameters through it. Here for simplicity we are serializing it into JSON but possibilities are lot more stay tuned for &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-bundling-auto-sync-javascript-model-with-mvc-model.html"&gt;tomorrow’s post to know how I wanted to use it&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now we are ready with custom bundle and transform type so following is the code which shows how to add this custom bundle to bundle collection.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;CustomBundle bundle = &lt;span class="kwrd"&gt;new&lt;/span&gt; CustomBundle(&lt;span class="str"&gt;"~/bundles/metainfo"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;bundle.MetaInfo = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;bundle.MetaInfo.Add(&lt;span class="str"&gt;"Blog"&lt;/span&gt;, &lt;span class="str"&gt;"dotnetExpertGuide.com"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;bundle.MetaInfo.Add(&lt;span class="str"&gt;"Author"&lt;/span&gt;, &lt;span class="str"&gt;"Nandip Makwana"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;bundles.Add(bundle);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-IVeJhYWpDVg/UJ6SwQsr5nI/AAAAAAAABAI/TiMrW3g0VLY/s1600/custom%2Bbundle.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-IVeJhYWpDVg/UJ6SwQsr5nI/AAAAAAAABAI/TiMrW3g0VLY/s1600/custom%2Bbundle.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h4&gt;What leads me to find the way of passing extra parameters and how I wanted to use it?&lt;/h4&gt;
&lt;p&gt;For simplicity and clear separation of topic I have written another post which shows &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-bundling-auto-sync-javascript-model-with-mvc-model.html"&gt;how I wanted to use this bundling approach with ASP.NET MVC application&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Check out this index post on &lt;a href="http://www.dotnetexpertguide.com/2013/04/aspnet-web-optimization-framework-article-series.html"&gt;ASP.NET Web Optimization Framework (a.k.a Bundling &amp; Minification)&lt;/a&gt; to read other post on same.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=H2rC2EWd8wk:-foHOSom1_M:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=H2rC2EWd8wk:-foHOSom1_M:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=H2rC2EWd8wk:-foHOSom1_M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=H2rC2EWd8wk:-foHOSom1_M:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=H2rC2EWd8wk:-foHOSom1_M:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=H2rC2EWd8wk:-foHOSom1_M:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=H2rC2EWd8wk:-foHOSom1_M:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=H2rC2EWd8wk:-foHOSom1_M:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=H2rC2EWd8wk:-foHOSom1_M:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/H2rC2EWd8wk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/6105398456408422051/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/11/aspnet-45-mvc-4-bundling-next-approach.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/6105398456408422051?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/6105398456408422051?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/H2rC2EWd8wk/aspnet-45-mvc-4-bundling-next-approach.html" title="ASP.NET 4.5 &amp; MVC 4 Bundling: Next Approach" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-uUm0vhrZ8Jc/UJ6Rn4WOeiI/AAAAAAAAA_8/6u1jtAMtmpw/s72-c/ASP.NET.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/11/aspnet-45-mvc-4-bundling-next-approach.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE4ER3Y5eCp7ImA9WhBUF04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-6656678354166726361</id><published>2012-11-10T10:00:00.000+05:30</published><updated>2013-05-05T12:25:06.820+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T12:25:06.820+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: ChildActionOnly action filter</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-O2giPn1QxGo/UIV0Cjoz4_I/AAAAAAAAA8A/4ISonLl0ZYQ/s1600/ChildActionOnly.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="ASP.NET MVC: ChildActionOnly" border="0" src="http://1.bp.blogspot.com/-O2giPn1QxGo/UIV0Cjoz4_I/AAAAAAAAA8A/4ISonLl0ZYQ/s1600/ChildActionOnly.png" title="ASP.NET MVC: ChildActionOnly" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;ChildActionOnly action filter confirms that specified action method should be only accessible by child request. Unlike &lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-nonaction-action-filter.html"&gt;NonAction&lt;/a&gt; filter, such methods are still treated as action method but it can’t be invoke as a parent request. More specific user can’t invoke it direct by requesting action name but we developer can invoke it through code.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Attribute Usage:&lt;/b&gt; Controller &amp; method&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[ChildActionOnly]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult About()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;We can also apply this action filter at controller level so all action method of specified controller will be accessible by only child request. &lt;/p&gt;
&lt;h4&gt;What is child request in ASP.NET MVC?&lt;/h4&gt;
&lt;p&gt;So now next question arise is what is child request? So child request means we can’t access it by direct url in other word we can’t use it to begin new request/response pipeline but we can use it as action method from within code where request/response pipeline are already initiated by some other request or action method. We can use such child action method as follow. &lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;@Html.Action(&lt;span class="str"&gt;"ChildActionMethod"&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&amp;nbsp;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;@{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    Html.RenderAction(&lt;span class="str"&gt;"ChildActionMethod"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If we try to access such method with direct url then it will throw an System.InvalidOperationException.&lt;/p&gt;
&lt;p&gt;Check out &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;ASP.NET MVC: Action filter series&lt;/a&gt; post to read about other available  action filters.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=le9uukLUW5w:PgMGzaZgo6c:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=le9uukLUW5w:PgMGzaZgo6c:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=le9uukLUW5w:PgMGzaZgo6c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=le9uukLUW5w:PgMGzaZgo6c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=le9uukLUW5w:PgMGzaZgo6c:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=le9uukLUW5w:PgMGzaZgo6c:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=le9uukLUW5w:PgMGzaZgo6c:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=le9uukLUW5w:PgMGzaZgo6c:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=le9uukLUW5w:PgMGzaZgo6c:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/le9uukLUW5w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/6656678354166726361/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-childactiononly-action-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/6656678354166726361?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/6656678354166726361?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/le9uukLUW5w/aspnet-mvc-childactiononly-action-filter.html" title="ASP.NET MVC: ChildActionOnly action filter" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-O2giPn1QxGo/UIV0Cjoz4_I/AAAAAAAAA8A/4ISonLl0ZYQ/s72-c/ChildActionOnly.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-childactiononly-action-filter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8AR3w9eyp7ImA9WhBUF04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-2585413937087496557</id><published>2012-11-08T10:00:00.000+05:30</published><updated>2013-05-05T12:24:06.263+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T12:24:06.263+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: AcceptVerbs action filter</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-8iMJq2o1JIw/UIV0BYKPqeI/AAAAAAAAA7o/4XohLkijWI8/s1600/AcceptVerbs.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="ASP.NET MVC: AcceptVerbs" border="0" src="http://4.bp.blogspot.com/-8iMJq2o1JIw/UIV0BYKPqeI/AAAAAAAAA7o/4XohLkijWI8/s1600/AcceptVerbs.png" title="ASP.NET MVC: AcceptVerbs" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;So far we have seen various action filter in ASP.NET MVC which allow us to restrict action method usage based on HTTP verb or method. But with the usage of &lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httpget-action-filter.html"&gt;HttpGet&lt;/a&gt;, &lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httppost-action-filter.html"&gt;HttpPost&lt;/a&gt;, &lt;a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httpput-action-filter.html"&gt;HttpPut&lt;/a&gt; or other such action filter, we are limited to only respective HTTP verb. But sometime we require that action method should be accessible by more than one HTTP verb but not all. This is the case where AcceptVerbs comes in picture.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;In this case, we can use AcceptVerbs action filter. Here we can specify list of HTTP verbs and action method would be accessible by only those verbs.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Attribute Usage:&lt;/b&gt; Only method&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult About()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In above example, action method will be accessible by only HTTP GET &amp; POST verbs. Following is the full list of possible value for AcceptVerbs&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;HttpVerbs.Get&lt;/li&gt;
&lt;li&gt;HttpVerbs.Post&lt;/li&gt;
&lt;li&gt;HttpVerbs.Put&lt;/li&gt;
&lt;li&gt;HttpVerbs.Delete&lt;/li&gt;
&lt;li&gt;HttpVerbs.Head&lt;/li&gt;
&lt;li&gt;HttpVerbs.Patch&lt;/li&gt;
&lt;li&gt;HttpVerbs.Options&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We can use any combination from above list with AcceptVerbs filter.&lt;/p&gt;
&lt;p&gt;Check out &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;ASP.NET MVC: Action filter series&lt;/a&gt; post to read about other available  action filters.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=uLJzQvsTMHQ:HFWNaoRVD1s:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=uLJzQvsTMHQ:HFWNaoRVD1s:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=uLJzQvsTMHQ:HFWNaoRVD1s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=uLJzQvsTMHQ:HFWNaoRVD1s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=uLJzQvsTMHQ:HFWNaoRVD1s:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=uLJzQvsTMHQ:HFWNaoRVD1s:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=uLJzQvsTMHQ:HFWNaoRVD1s:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=uLJzQvsTMHQ:HFWNaoRVD1s:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=uLJzQvsTMHQ:HFWNaoRVD1s:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/uLJzQvsTMHQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/2585413937087496557/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-acceptverbs-action-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/2585413937087496557?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/2585413937087496557?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/uLJzQvsTMHQ/aspnet-mvc-acceptverbs-action-filter.html" title="ASP.NET MVC: AcceptVerbs action filter" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-8iMJq2o1JIw/UIV0BYKPqeI/AAAAAAAAA7o/4XohLkijWI8/s72-c/AcceptVerbs.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-acceptverbs-action-filter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEAESXc9cSp7ImA9WhBUF04.&quot;"><id>tag:blogger.com,1999:blog-7819331473560289523.post-8242527735171651823</id><published>2012-10-29T19:30:00.000+05:30</published><updated>2013-05-05T12:21:48.969+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-05T12:21:48.969+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><title>ASP.NET MVC: HttpPatch action filter</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-FCxs__IKmk8/UI3yNRncmKI/AAAAAAAAA_g/s6PGlBFkjPU/s1600/HttpPatch.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="ASP.NET MVC: HttpPatch" border="0" src="http://1.bp.blogspot.com/-FCxs__IKmk8/UI3yNRncmKI/AAAAAAAAA_g/s6PGlBFkjPU/s1600/HttpPatch.png" title="ASP.NET MVC: HttpPatch" /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt; HttpPatch action filter attribute confirm that specified method should be available only via HTTP PATCH request. HttpPatch action filter is new in &lt;a href="http://www.dotnetexpertguide.com/2011/09/aspnet-mvc-4-article-series.html"&gt;MVC 4&lt;/a&gt;. HTTP &lt;a href="http://tools.ietf.org/html/rfc5789" target="_blank"&gt;PATCH&lt;/a&gt; verb is relatively new and it is used to modify an existing HTTP resource. HTTP PUT allow us to create or replace existing HTTP resource but we cant modify existing resource with HTTP PUT. This is where HTTP PATCH comes in picture.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Attribute Usage:&lt;/b&gt; Only method&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;&lt;div id="codeSnippet" class="csharpcode"&gt;
&lt;pre class="alt"&gt;[HttpPatch]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult About()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;{&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Alike other action filter, We can’t access such method with other than HTTP PATCH verb. If we try to access it with other HTTP verb then it will fail and return HTTP 404 not found error.&lt;/p&gt;
&lt;p&gt;Check out &lt;a href="http://www.dotnetexpertguide.com/2012/11/aspnet-mvc-action-filter-series.html"&gt;ASP.NET MVC: Action filter series&lt;/a&gt; post to read about other available  action filters.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;You can follow me on &lt;a href="https://twitter.com/NandipMakwana" target="_blank"&gt;twitter&lt;/a&gt; for latest link and update on &lt;a href="http://www.dotnetexpertguide.com/search/label/ASP.NET"&gt;ASP.NET&lt;/a&gt; &amp; &lt;a href="http://www.dotnetexpertguide.com/search/label/MVC"&gt;MVC&lt;/a&gt;.&lt;/i&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=rGzHmAkbXmI:AL4eNEfguDY:iuKBeV4sXr0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=rGzHmAkbXmI:AL4eNEfguDY:iuKBeV4sXr0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=rGzHmAkbXmI:AL4eNEfguDY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=rGzHmAkbXmI:AL4eNEfguDY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=rGzHmAkbXmI:AL4eNEfguDY:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=rGzHmAkbXmI:AL4eNEfguDY:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=rGzHmAkbXmI:AL4eNEfguDY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Dotnetexpertguide?a=rGzHmAkbXmI:AL4eNEfguDY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Dotnetexpertguide?i=rGzHmAkbXmI:AL4eNEfguDY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Dotnetexpertguide/~4/rGzHmAkbXmI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.dotnetexpertguide.com/feeds/8242527735171651823/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httppatch-action-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/8242527735171651823?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7819331473560289523/posts/default/8242527735171651823?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Dotnetexpertguide/~3/rGzHmAkbXmI/aspnet-mvc-httppatch-action-filter.html" title="ASP.NET MVC: HttpPatch action filter" /><author><name>Nandip Makwana</name><uri>https://plus.google.com/100983452498554383356</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-pDb4IK6WZRs/AAAAAAAAAAI/AAAAAAAAAf4/0K7LrsiXehI/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-FCxs__IKmk8/UI3yNRncmKI/AAAAAAAAA_g/s6PGlBFkjPU/s72-c/HttpPatch.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-httppatch-action-filter.html</feedburner:origLink></entry></feed>
