<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Schotime.net &#187; MVC</title>
	<atom:link href="http://schotime.net/blog/index.php/tag/mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://schotime.net/blog</link>
	<description>All Things .Net and Me</description>
	<lastBuildDate>Sun, 20 Nov 2011 01:44:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PetaPoco Performance Statistics</title>
		<link>http://schotime.net/blog/index.php/2011/05/03/petapoco-performance-statistics/</link>
		<comments>http://schotime.net/blog/index.php/2011/05/03/petapoco-performance-statistics/#comments</comments>
		<pubDate>Tue, 03 May 2011 13:46:09 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[PetaPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/05/03/petapoco-performance-statistics/</guid>
		<description><![CDATA[The other day Sam from stackoverflow blogged about a slow page caused by a combination of problems resulting in them using Dapper to map native SQL to the objects resulting in a nice performance improvement. I liked how he made the queries executed for the current request display in html comments in the html source, [...]]]></description>
			<content:encoded><![CDATA[<p>The other day <a href="http://samsaffron.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/samsaffron.com/?referer=');">Sam</a> from stackoverflow <a href="http://samsaffron.com/archive/2011/05/02/A+day+in+the+life+of+a+slow+page+at+Stack+Overflow" target="_blank" onclick="pageTracker._trackPageview('/outgoing/samsaffron.com/archive/2011/05/02/A+day+in+the+life+of+a+slow+page+at+Stack+Overflow?referer=');">blogged</a> about a slow page caused by a combination of problems resulting in them using <a href="http://code.google.com/p/dapper-dot-net/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/dapper-dot-net/?referer=');">Dapper</a> to map native SQL to the objects resulting in a nice performance improvement.</p>
<p>I liked how he made the queries executed for the current request display in html comments in the html source, so I thought I would see if I could implement the same thing with <a href="http://www.toptensoftware.com/petapoco/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/petapoco/?referer=');">PetaPoco</a>. I intend to go through how I implemented the following in future posts (after I go through some basics), but for the moment I’ll give you a quick screen grab of what it looks like. Thanks goes to Sam for providing the inspiration.</p>
<p><a href="http://schotime.net/blog/wp-content/uploads/2011/05/petapoco_db_stats.jpg" onclick="pageTracker._trackPageview('/outgoing/schotime.net/blog/wp-content/uploads/2011/05/petapoco_db_stats.jpg?referer=');"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="petapoco_db_stats" border="0" alt="petapoco_db_stats" src="http://schotime.net/blog/wp-content/uploads/2011/05/petapoco_db_stats_thumb.jpg" width="948" height="586" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/05/03/petapoco-performance-statistics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Integrating xVal Validation with Linq-to-Sql</title>
		<link>http://schotime.net/blog/index.php/2009/03/31/integrating-xval-validation-with-linq-to-sql/</link>
		<comments>http://schotime.net/blog/index.php/2009/03/31/integrating-xval-validation-with-linq-to-sql/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 13:58:00 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[xVal]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/03/31/integrating-xval-validation-with-linq-to-sql/</guid>
		<description><![CDATA[In a previous post I showed you how you can use xVal and the IDataErrorInfo class to add validation to your Asp.net MVC website. In this post I will extend that to Linq-to-Sql and the classes it generates. The northwind database has a suppliers table. The info contained below is using that table with linq-to-sql. [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous <a href="http://schotime.net/blog/index.php/2009/03/05/validation-with-aspnet-mvc-xval-idataerrorinfo/" onclick="pageTracker._trackPageview('/outgoing/schotime.net/blog/index.php/2009/03/05/validation-with-aspnet-mvc-xval-idataerrorinfo/?referer=');">post</a> I showed you how you can use xVal and the IDataErrorInfo class to add validation to your Asp.net MVC website. In this post I will extend that to Linq-to-Sql and the classes it generates.</p>
<p>The northwind database has a suppliers table. The info contained below is using that table with linq-to-sql. </p>
<p>After adding the table to the designer, a Supplier class gets constructed in the background. This class is a partial class which means we can add to it without changing the code auto-generated in the designer.cs file.</p>
<p>We can then create a partial class called Supplier inheriting from Custom Validation and add a MetadataType attribute to it. This attribute specifies the class for which use for validating the Supplier class.</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td style="background: black" valign="top" width="400">
<pre class="code"><span style="background: black; color: white">    [</span><span style="background: black; color: #ffc66d">MetadataType</span><span style="background: black; color: white">(</span><span style="background: black; color: #cc7832">typeof</span><span style="background: black; color: white">(</span><span style="background: black; color: #ffc66d">SupplierValidation</span><span style="background: black; color: white">))]
</span><span style="background: black; color: #cc7832">    public partial class </span><span style="background: black; color: #ffc66d">Supplier</span><span style="background: black; color: white"> : </span><span style="background: black; color: #ffc66d">CustomValidation</span><span style="background: black; color: #ffc66d">
</span><span style="background: black; color: white">    {
    }</span></pre>
</td>
</tr>
</tbody>
</table>
<p>We can then create the SupplierValidation class specifying the properties of the Supplier class we would like to be validated. For instance here I only want to validate the ContactName and the ContactTitle of the Supplier.</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td style="background: black" valign="top" width="400">
<pre class="code"><span style="background: black; color: white">    </span><span style="background: black; color: #cc7832">    public class </span><span style="background: black; color: #ffc66d">SupplierValidation
    </span><span style="background: black; color: white">{
        [</span><span style="background: black; color: #ffc66d">Required</span><span style="background: black; color: white">]
        </span><span style="background: black; color: #cc7832">public string </span><span style="background: black; color: white">ContactName { </span><span style="background: black; color: #cc7832">get</span><span style="background: black; color: white">; </span><span style="background: black; color: #cc7832">set</span><span style="background: black; color: white">; }

        [</span><span style="background: black; color: #ffc66d">Required</span><span style="background: black; color: white">, </span><span style="background: black; color: #ffc66d">Range</span><span style="background: black; color: white">(</span><span style="background: black; color: #6897bb">0</span><span style="background: black; color: white">, </span><span style="background: black; color: #6897bb">10</span><span style="background: black; color: white">)]
        </span><span style="background: black; color: #cc7832">public string </span><span style="background: black; color: white">ContactTitle { </span><span style="background: black; color: #cc7832">get</span><span style="background: black; color: white">; </span><span style="background: black; color: #cc7832">set</span><span style="background: black; color: white">; }
    }</span></pre>
</td>
</tr>
</tbody>
</table>
<p>This specifies that both fields are required and that the ContactTitle cannot be more than 10 characters in length. </p>
<p>The other benefit of using the buddy class here is that if you need to regenerate a table in the linq-to-sql designer, you won’t lose your changes because they’re contained in a separate file.</p>
<p>From here when a Supplier gets passed to in as a parameter on a Controller action it will be validated using the rules in the Supplier Validation class. </p>
<p>Cheers,<br />
  <br />Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2009/03/31/integrating-xval-validation-with-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running ASP.NET MVC Applications Under IIS6</title>
		<link>http://schotime.net/blog/index.php/2008/10/18/running-aspnet-mvc-applications-under-iis6/</link>
		<comments>http://schotime.net/blog/index.php/2008/10/18/running-aspnet-mvc-applications-under-iis6/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 09:41:29 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Routing]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2008/10/18/running-aspnet-mvc-applications-under-iis6/</guid>
		<description><![CDATA[Yes&#8230;Finally&#8230;I have full control of my HTML again, but am still able to work with a great language like C#. MVC is here and its great. I&#8217;m absolutely loving it. But how the heck do you get it to work under IIS6. What if I want extensionless URL&#8217;s? Here is a few options for you. [...]]]></description>
			<content:encoded><![CDATA[<p>Yes&#8230;Finally&#8230;I have full control of my HTML again, but am still able to work with a great language like C#. MVC is here and its great. I&#8217;m absolutely loving it. But how the heck do you get it to work under IIS6. What if I want extensionless URL&#8217;s? Here is a few options for you.</p>
<p><strong>Option 1:      <br /></strong>Running IIS with Wildcard Application mapping.</p>
<p>This option allows extensionless URL&#8217;s but a what performance price. Every single request including images, files and css etc. will get passed through the aspnet_isapi.dll. For small sites this may not be a huge issue, but small sites soon because large sites and this then becomes an issue.</p>
<p>I&#8217;m not going to run through how to do this, because there are already some nice blogs about this and I don&#8217;t really recommend this option.</p>
<p><strong>Option 2:      <br /></strong>Running IIS with .mvc (or whatever you like) extensions.</p>
<p>I started out running my site (schotime.net) like this, however in the end I decided on Option 3.    <br />URLs look like this.&#160;&#160; /Home.mvc/Index&#160;&#160; rather than /Home/Index&#160; which is not that bad but again not as nice as the latter.</p>
<p>Anyways here&#8217;s how you set this up.    <br />Firstly your global.asax.cs should look like this.</p>
<table style="background: black" cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="400">
<pre class="code"><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Collections.Generic;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Linq;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web.Mvc;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web.Routing;

</span><span style="background: black; color: #cc7832">namespace </span><span style="background: black; color: white">MVCApplication1
{
    </span><span style="background: black; color: #cc7832">public class </span><span style="background: black; color: #ffc66d">MvcApplication </span><span style="background: black; color: white">: System.Web.HttpApplication
    {
        </span><span style="background: black; color: #cc7832">public static void </span><span style="background: black; color: white">RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute(</span><span style="background: black; color: #a5c25c">&quot;{resource}.axd/{*pathInfo}&quot;</span><span style="background: black; color: white">);

            routes.MapRoute(
                </span><span style="background: black; color: #a5c25c">&quot;Default&quot;</span><span style="background: black; color: white">,                                              </span><span style="background: black; color: gray">
                </span><span style="background: black; color: #a5c25c">&quot;{controller}.mvc/{action}/{id}&quot;</span><span style="background: black; color: white">,                       </span><span style="background: black; color: gray">
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a5c25c">&quot;Home&quot;</span><span style="background: black; color: white">, action = </span><span style="background: black; color: #a5c25c">&quot;Index&quot;</span><span style="background: black; color: white">, id = </span><span style="background: black; color: #a5c25c">&quot;&quot; </span><span style="background: black; color: white">}  </span><span style="background: black; color: gray">
            </span><span style="background: black; color: white">);

            routes.MapRoute(
                </span><span style="background: black; color: #a5c25c">&quot;Defaultest&quot;</span><span style="background: black; color: white">,                                           </span><span style="background: black; color: gray">
                </span><span style="background: black; color: #a5c25c">&quot;Default.aspx&quot;</span><span style="background: black; color: white">,                                         </span><span style="background: black; color: gray">
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a5c25c">&quot;Home&quot;</span><span style="background: black; color: white">, action = </span><span style="background: black; color: #a5c25c">&quot;Index&quot;</span><span style="background: black; color: white">, id = </span><span style="background: black; color: #a5c25c">&quot;&quot; </span><span style="background: black; color: white">}  </span><span style="background: black; color: gray">
            </span><span style="background: black; color: white">);

        }

        </span><span style="background: black; color: #cc7832">protected void </span><span style="background: black; color: white">Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
            RouteTable.Routes.RouteExistingFiles = </span><span style="background: black; color: #cc7832">true</span><span style="background: black; color: white">;
        }
    }
}</span></pre>
<p>        <a href="http://11011.net/software/vspaste" onclick="pageTracker._trackPageview('/outgoing/11011.net/software/vspaste?referer=');"></a></td>
</tr>
</tbody>
</table>
<p>This will get you started. All you need to do then is map the extension .mvc to the aspnet_isapi.dll in IIS under Home Directory -&gt; Configuration -&gt; Mappings or use an already mapped extension like .aspx and your mvc application should work.</p>
<p><strong>Option 3:<br />
    <br /></strong>This option requires the use of a clever isapi filter to rewrite the URLs. </p>
<p>I originally read an article on <a href="http://biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/?referer=');">Bia Securities</a> which uses the Isapi_rewrite 3rd party plugin however, Isapi_rewrite is not free so I thought I would find a suitable open source solution. Here it is: Ionic Rewriter -&gt; <a title="http://www.codeplex.com/IIRF" href="http://www.codeplex.com/IIRF" onclick="pageTracker._trackPageview('/outgoing/www.codeplex.com/IIRF?referer=');">http://www.codeplex.com/IIRF</a> </p>
<p>It works in much the same way as the isapi_rewrite but will a few little differences. Once you download the IsapiRewrite4.dll, place the dll in a directory eg. C:\WINDOWS\system32\inetsrv\IIRF and run through the installation instructions included in the download (readme.txt) under Installation. Next comes the configuration. Firstly here is the IsapiRewrite4.ini configuration file ported from the <a href="http://biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/?referer=');">Bia Securities</a> article.</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="400">
<p>#RewriteLog&#160; c:\temp\iirfLog.out<br />
          <br />#RewriteLogLevel 3 </p>
<p>RewriteRule ^/Default\.aspx /Home.mvc [I,L] </p>
<p>RewriteRule ^/$ /Home.mvc [I,L] </p>
<p>RewriteRule ^/([\w]+)$ /$1.mvc [I,L] </p>
<p>RewriteRule ^/(?!Content)([\w]*)/(.*) /$1.mvc/$2 [I,L]</p>
</td>
</tr>
</tbody>
</table>
<p>The [I,L] stands for a case-insensitive match and to stop processing if the current rule is a match.</p>
<p><strong>Important Note:<br />
    <br /></strong>Any physical files that you directly linked to should not be routed. In my MVC folder system I store all of these files under the /Content directory. Wherever you store your files replace the text Content with the folder that your files reside. otherwise images, css etc. will fail to display. </p>
<p>Now all that&#8217;s left to do is to modify the global.asax.cs to support this. </p>
<table style="background: black" cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="400">
<pre class="code"><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Collections.Generic;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Linq;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web.Mvc;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web.Routing;

</span><span style="background: black; color: #cc7832">namespace </span><span style="background: black; color: white">MVCApplication1
{
    </span><span style="background: black; color: #cc7832">public class </span><span style="background: black; color: #ffc66d">MvcApplication </span><span style="background: black; color: white">: System.Web.HttpApplication
    {
        </span><span style="background: black; color: #cc7832">public static void </span><span style="background: black; color: white">RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute(</span><span style="background: black; color: #a5c25c">&quot;{resource}.axd/{*pathInfo}&quot;</span><span style="background: black; color: white">);

            routes.MapRoute(
                </span><span style="background: black; color: #a5c25c">&quot;Default&quot;</span><span style="background: black; color: white">,                                              </span><span style="background: black; color: gray">// Route name
                </span><span style="background: black; color: #a5c25c">&quot;{controller}/{action}/{id}&quot;</span><span style="background: black; color: white">,                           </span><span style="background: black; color: gray">// URL with parameters
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a5c25c">&quot;Home&quot;</span><span style="background: black; color: white">, action = </span><span style="background: black; color: #a5c25c">&quot;Index&quot;</span><span style="background: black; color: white">, id = </span><span style="background: black; color: #a5c25c">&quot;&quot; </span><span style="background: black; color: white">}, </span><span style="background: black; color: gray">// Parameter defaults
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a31515">@&quot;[^\.]*&quot; </span><span style="background: black; color: white">}
            );

            routes.MapRoute(
                </span><span style="background: black; color: #a5c25c">&quot;Defaultmvc&quot;</span><span style="background: black; color: white">,                                               </span><span style="background: black; color: gray">// Route name
                </span><span style="background: black; color: #a5c25c">&quot;{controller}.mvc/{action}/{id}&quot;</span><span style="background: black; color: white">,                           </span><span style="background: black; color: gray">// URL with parameters
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a5c25c">&quot;Home&quot;</span><span style="background: black; color: white">, action = </span><span style="background: black; color: #a5c25c">&quot;Index&quot;</span><span style="background: black; color: white">, id = </span><span style="background: black; color: #a5c25c">&quot;&quot; </span><span style="background: black; color: white">},     </span><span style="background: black; color: gray">// Parameter defaults
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a31515">@&quot;[^\.]*&quot; </span><span style="background: black; color: white">}
            );
        }

        </span><span style="background: black; color: #cc7832">protected void </span><span style="background: black; color: white">Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}</span></pre>
</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong>&#160; The line with this on it -&gt; new { controller = @&quot;[^\.]*&quot; }&#160;&#160; is very important. The routes won&#8217;t work without it. </p>
<p>And that&#8217;s it! You&#8217;re done.<br />
  <br />Personally I like the last option but if you have no access to your hosting web server then Option 2 is probably the best.</p>
<p>Schotime</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2008/10/18/running-aspnet-mvc-applications-under-iis6/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

