<?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>Thu, 01 Jul 2010 14:42:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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. 
After [...]]]></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/">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.
Option [...]]]></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>
