<?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>C.M. Jackson .Net &#187; ASP.NET MVC</title>
	<atom:link href="http://www.cmjackson.net/tag/asp-net-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cmjackson.net</link>
	<description>Web Design, Programming, Tutorials</description>
	<lastBuildDate>Tue, 13 Dec 2011 17:38:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Cricket.Net: Part 3 &#8211; Unit Testing</title>
		<link>http://www.cmjackson.net/2011/12/13/cricket-net-part-3-unit-testing/</link>
		<comments>http://www.cmjackson.net/2011/12/13/cricket-net-part-3-unit-testing/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 17:33:37 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=490</guid>
		<description><![CDATA[Summary Cricket.Net is a new open source project that I&#8217;ve started on Codeplex. It will be a web application that will be used for tracking software bugs. Cricket.Net will be written in C# using HTML5, ASP.NET MVC 3, Entity Framework 4.1 Code First, StructureMap, and the Onion Architecture. This project will be an example application [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Summary</strong><br />
Cricket.Net is a new open source project that I&#8217;ve started on Codeplex. It will be a web application that will be used for tracking software bugs. Cricket.Net will be written in C# using HTML5, ASP.NET MVC 3, Entity Framework 4.1 Code First, StructureMap, and the Onion Architecture. This project will be an example application to demonstrate how to use these technologies together to build a web application from the ground up.</p>
<p>I’ll also be going through using Mercurial both on my system and pushing changes to the Codeplex site.</p>
<p>Cricket.Net Series:</p>
<ul>
<li><a href="http://www.cmjackson.net/2011/10/12/cricket-net-part-1-setting-up-the-initial-project/">Part 1: Setting up the initial project</a></li>
<li><a href="http://www.cmjackson.net/2011/10/13/cricket-net-part-2-design-discussion/">Part 2: Design Discussion</a></li>
<li>Part 3: Unit Testing</li>
</ul>
<p><strong>Unit Testing Thoughts</strong><br />
The idea behind unit testing is to write a very simple piece of code to test your business logic for one condition.  The test either passes or fails.  As you build your application, you may have hundreds or thousands of these tests.  By keeping them very simple, and not running any time intensive operations such as I/O, these tests will be able to execute very quickly and give you an indication that your program is working correctly.</p>
<p>Unit Tests become most useful when your application has been completed for a number of months and then a required change is needed.  As you modify your code, you can re-run your unit tests to make sure your new modifications have not broken your program in some other area.</p>
<p>The difficult part of unit testing is thinking of all the different angles to test your piece of code.</p>
<p>As you write your tests and develop your application, you will undoubtedly break some of the tests that you had previously written.  These will then need to be revised.  This is the process you will go through to fully flesh out your application and develop it from a user (of the code) perspective.</p>
<p>I usually begin by writing all my tests against the Controllers since that is the entry point to the things my application will do.  I also try to write tests against the requirements of the application only.  If you test all of an application&#8217;s requirements, then you are making sure the application is doing what your customer wants it to do.  There is no need to test 100% of the code you write.  As mentioned above, you will break unit tests as you develop your application and continually have to revise them.  Revising tests that cover 100% of your code could be very time-consuming.</p>
<p><strong>Unit Test Controller Shell</strong><br />
Since we&#8217;ll be testing Requirements, the first thing I do is create a new folder in the Unit Test project called Requirements.  There is currently a Controllers folder that we will remove later on.</p>
<p>Next, create a new Class item called ApplicationControllerRequirements.</p>
<p><a href="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_01.png"><img class="alignnone size-medium wp-image-491" title="part3_01" src="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_01-300x207.png" alt="" width="300" height="207" /></a></p>
<p>The new class will need to be modified for unit testing. Below is the basic shell for a unit testing class.</p>
<pre class="brush: vb;">
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Cricket.UnitTests.Requirements
{
  [TestClass]
  public class ApplicationControllerRequirements
  {
    [TestInitialize]
    public void Setup()
    {
      //This method runs before each test method.
    }

    #region Test Group

    [TestMethod]
    public void unit_test_method()
    {
      //Arrange.

      //Act.

      //Assert.
    }

    #endregion
  }
}
</pre>
<p>There are three attributes being used on this class: TestClass, TestInitialize, and TestMethod.</p>
<ul>
<li><strong>TestClass</strong> &#8211; Signals this is a unit testing class.</li>
<li><strong>TestInitialize</strong> &#8211; This is an initialization method that is executed before each test method.</li>
<li><strong>TestMethod</strong> &#8211; This is a unit test function.</li>
</ul>
<p>A unit test only tests one condition and there may be many conditions we need to test for, so I like to group my tests together using regions. These can be collapsed out of the way within Visual Studio to make it easier to work on other unit tests without the unwanted ones getting in the way.</p>
<p>Within a test method, there are three things that need to be done:</p>
<ul>
<li><strong>Arrange</strong> &#8211; This consists of any mocking or setup tasks.</li>
<li><strong>Act</strong> &#8211; This is the execution of the action you are testing.</li>
<li><strong>Assert</strong> &#8211; This is the verification you received the desired result.</li>
</ul>
<p><strong>Writing The First Unit Test<br />
</strong>First we will start with a very simple test against the Index action of the controller. This is the default action that is called if none is specified in the application&#8217;s URL.</p>
<p><a href="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_02.png"><img class="alignnone size-full wp-image-499" title="part3_02" src="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_02.png" alt="" width="429" height="181" /></a></p>
<p>We&#8217;re going to test if the Index controller returns a ViewResult. Notice the compiler now has an error on the &#8220;controller&#8221; object. This is because we haven&#8217;t created it yet. One nice aspect of TDD (Test Driven Development) is you think about how the interface to your code is used, and then develop the code afterwards.  Now we know we need to create a &#8220;controller&#8221; object and it needs to have a method called &#8220;Index&#8221;.</p>
<p>Since the initialization of the controller will need to be done for nearly all tests in this class, we&#8217;ll add that to the Setup() method.</p>
<p><a href="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_03.png"><img class="alignnone size-full wp-image-500" title="part3_03" src="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_03.png" alt="" width="439" height="549" /></a></p>
<p>Now the compiler is showing errors on the &#8220;ApplicationController&#8221; class.  We need to create the new controller in the main project.</p>
<ul>
<li>Right-click on the Controllers folder in the main project.</li>
<li>Select Add, then Controller.</li>
<li>Type in the Controller Name: ApplicationController and click Add. (Leaving the Template set on Empty Controller)</li>
<li>In your unit test class, add the using statement: <em>using Cricket.Controllers;</em></li>
<li>Under the Unit Test method, add a cast to the &#8220;Act&#8221; line: <em>ViewResult result = (ViewResult)controller.Index();</em></li>
<li>Also, don&#8217;t forget to change the name of your unit test method to something meaningful. The more description you can put in this method name, the better.</li>
</ul>
<p><strong>Running Your Test</strong><br />
Ideally, you want to see your test fail first, to make sure you didn&#8217;t accidentally write a test that can never fail.</p>
<p>We can quickly test this by adding the following line to our Index method on the ApplicationController:</p>
<pre class="brush: vb;">
return RedirectToAction(&quot;Index&quot;);
</pre>
<p>A ViewResult is expected in the test, so now it will fail.</p>
<p><a href="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_03-1.png"><img class="alignnone size-full wp-image-510" title="part3_03-1" src="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_03-1.png" alt="" width="538" height="81" /></a></p>
<p>After you have verified the test has failed, change the Index method back to the following:</p>
<pre class="brush: vb;">
        public ActionResult Index()
        {
            return View();
        }
</pre>
<p>Now, your test should pass.<br />
<a href="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_04.png"><img class="alignnone size-full wp-image-503" title="part3_04" src="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_04.png" alt="" width="539" height="93" /></a><br />
<strong></strong></p>
<p><strong>Another Test<br />
</strong>Next, we&#8217;ll add another very simple test to verify the correct view is being returned from the Index method.</p>
<pre class="brush: vb;">
        [TestMethod]
        public void index_action_should_return_the_index_view()
        {
            //Arrange.

            //Act.
            ViewResult result = (ViewResult)controller.Index();

            //Assert.
            Assert.AreEqual(&quot;Index&quot;, result.ViewName, &quot;result.ViewName&quot;);
        }
</pre>
<p>Running this test will fail because the Index method is not returning a specific view. To change this, modify the Index method to show:</p>
<pre class="brush: vb;">
        public ActionResult Index()
        {
            return View(&quot;Index&quot;);
        }
</pre>
<p>Now the test will pass because we are specifying a view to display.<br />
<a href="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_05.png"><img class="alignnone size-full wp-image-504" title="part3_05" src="http://www.cmjackson.net/wp-content/uploads/2011/12/part3_05.png" alt="" width="535" height="99" /></a><br />
<strong></strong></p>
<p><strong>Final Thoughts<br />
</strong>Unit Testing does take some time to get the hang of it. It is well worth it in the long run to know you can modify your program to add new features without breaking the current functionality.</p>
<p>As we develop this application, these tests will become more complex, but by focusing on one result and writing multiple tests for each action, we can work through it.</p>
<p>The empty &#8220;Arrange&#8221; comment for each of these tests is a place holder for mocking objects we may need to place there in the future. Typically, Unit Testing developers say to place all setup code in the arrange.  I like to place common setup tasks that will happen for each test in the &#8220;Setup&#8221; method where I only have to code them once.  If there is a specific setup task needed for a single test, then I will place that under the &#8220;Arrange&#8221; comment.</p>
<p>Visit the project site at: <a href="http://cricket.codeplex.com">http://cricket.codeplex.com</a>.<br />
Download the source code from this post at:<br />
<a href="http://cricket.codeplex.com/SourceControl/changeset/changes/df77b3e9d546">http://cricket.codeplex.com/SourceControl/changeset/changes/df77b3e9d546</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2011/12/13/cricket-net-part-3-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cricket.Net: Part 2 &#8211; Design Discussion</title>
		<link>http://www.cmjackson.net/2011/10/13/cricket-net-part-2-design-discussion/</link>
		<comments>http://www.cmjackson.net/2011/10/13/cricket-net-part-2-design-discussion/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 14:03:47 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Website Development]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Onion Architecture]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=479</guid>
		<description><![CDATA[Summary Cricket.Net is a new open source project that I&#8217;ve started on Codeplex. It will be a web application that will be used for tracking software bugs. Cricket.Net will be written in C# using HTML5, ASP.NET MVC 3, Entity Framework 4.1 Code First, StructureMap, and the Onion Architecture. This project will be an example application [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Summary</strong><br />
Cricket.Net is a new open source project that I&#8217;ve started on Codeplex. It will be a web application that will be used for tracking software bugs. Cricket.Net will be written in C# using HTML5, ASP.NET MVC 3, Entity Framework 4.1 Code First, StructureMap, and the Onion Architecture. This project will be an example application to demonstrate how to use these technologies together to build a web application from the ground up.</p>
<p>I&#8217;ll also be going through using Mercurial both on my system and pushing changes to the Codeplex site.</p>
<p>Cricket.Net Series:</p>
<ul>
<li><a href="http://www.cmjackson.net/2011/10/12/cricket-net-part-1-setting-up-the-initial-project/">Part 1: Setting up the initial project</a></li>
<li>Part 2: Design Discussion<br />
<a href="http://www.cmjackson.net/2011/12/13/cricket-net-part-3-unit-testing/">Part 3: Unit Testing</a></li>
</ul>
<p><strong>What will the application do?</strong><br />
I&#8217;m going to take a step back before continuing with the code and look at what this application is suppose to do. I don&#8217;t need to determine everything up front, instead I&#8217;m going to use an Agile approach and lay down some basic requirements for what the system is suppose to do and if those change as the development progresses, that is fine.</p>
<p>Ususally the first thing I do is think about what information the application needs to store. Cricket.Net is a bug tracking program, so it will need to store information on a specific bug and what application the bug occurred in. I&#8217;m also going to want to track dates for when the bug was created and resolved, the version of the application the bug occurred in and maybe a list of one or more assignees who are working on resolving the bug.</p>
<p>Next, I&#8217;m going to open up Visio and separate these ideas into objects on a database model diagram. Since I&#8217;ve already created my solution folder, I&#8217;m going to add a folder within it called !Design. I&#8217;ll place all of my design files here to keep them with the solution when I update the Mercurial repository.</p>
<p>You don&#8217;t necessarily need to create a diagram of the database, you could just write-up the code using Entity Framework: Code First, but it is nice for non-programmers to have something to look at. Also, complex databases with many relationships can be difficult to work with if you don&#8217;t have a diagram to look at.</p>
<p><a href="http://www.cmjackson.net/wp-content/uploads/2011/10/Database-Diagram.jpg"><img class="alignnone size-medium wp-image-481" title="Database Diagram" src="http://www.cmjackson.net/wp-content/uploads/2011/10/Database-Diagram-300x252.jpg" alt="" width="300" height="252" /></a></p>
<p><strong>Onion Architecture and StructureMap</strong><br />
Now I&#8217;d like to talk for a minute about the Onion Architecture.  Structuring an application in this way separates the business logic from the web and infrastructure components in a way that limits their dependencies on each other. Take a look at the following diagram:</p>
<p><a href="http://www.cmjackson.net/wp-content/uploads/2011/10/Onion-Architecture.jpg"><img class="alignnone size-medium wp-image-482" title="Onion Architecture" src="http://www.cmjackson.net/wp-content/uploads/2011/10/Onion-Architecture-300x125.jpg" alt="" width="300" height="125" /></a></p>
<p>The blue boxes represent a project within the solution. The arrows point to their dependencies. Notice how all projects depend on Core. This is where the business logic classes and interfaces are found. Also, notice how the Web project (in this case will be MVC 3) does not depend on Infrastructure (where the database repositories reside). There is an indirect dependency through the DependencyInjection project. This is where StructureMap (or another IoC framework) lives. StructureMap will wire-up the dependencies between the Web and Infrastructure frameworks using the interfaces found in the Core project.</p>
<p>Why go through all this work to setup your project this way? Encapsulation of components that could be replacable in the future makes it easy to upgrade an application to those new componenets. With Onion Architecture you could switch the entire application over to a different database server and only have to modify the database classes found in the Infrastructure project. As long as the interfaces do not change for those classes, the reset of the application will work as it did previously. This can save much time over rewriting the entire application because the db code is embedded everywhere.</p>
<p>The UI component could be changed as well (in this case the Web project) for a console application. The Core and Infrastructure will function the same, but the application would appear totally different.</p>
<p>Projects Summary:</p>
<ul>
<li><strong>UnitTests</strong> &#8211; As the name implies, it contains all unit testing code. The Moq mocking framework will be used here.</li>
<li><strong>Web</strong> &#8211; This is the user interface project. This contains the controllers, views, view models, and wrapper classes around MVC or web specific operations.</li>
<li><strong>Core</strong> &#8211; This contains all interfaces for the application and business logic including: the domain model and service classes.</li>
<li><strong>DependencyInjection</strong> - This contains the classes needed by StructureMap. StructureMap will register all interfaces and concrete classes used in the application.</li>
<li><strong>Infrastructure</strong> &#8211; This contains any IO wrappers or classes using 3rd party projects (including our own common projects).</li>
</ul>
<p><strong>Unit Testing</strong><br />
When starting a project, I try to get in the habbit of coding a Unit Test first, before anything else. This helps me think about how I want to use a method before I worry about how the method works. This tends to lead to an overall better design of the application. I also try to adhere to the SOLID principles, DRY, and YAGNI by only coding what is needed at the time.</p>
<p>Unit Tests should also be very simple. Test for one condition to be met and pass or fail.</p>
<p><strong>Requirements</strong></p>
<ul>
<li>Allow users to manage Applications (including adding different versions for each).</li>
<li>Allow users to manage their issues.</li>
<li>Allow users to be managed by users.</li>
<li>(Managing each of these includes listing, adding, creating, editing, and deleting).</li>
</ul>
<p>Visit the project site at: <a href="http://cricket.codeplex.com">http://cricket.codeplex.com</a>.<br />
Download the source code from this post at: <a href="http://cricket.codeplex.com/SourceControl/changeset/changes/a115ce901573">http://cricket.codeplex.com/SourceControl/changeset/changes/a115ce901573</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2011/10/13/cricket-net-part-2-design-discussion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cricket.Net: Part 1 &#8211; Setting up the initial project</title>
		<link>http://www.cmjackson.net/2011/10/12/cricket-net-part-1-setting-up-the-initial-project/</link>
		<comments>http://www.cmjackson.net/2011/10/12/cricket-net-part-1-setting-up-the-initial-project/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 19:50:32 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Website Development]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=467</guid>
		<description><![CDATA[Summary Cricket.Net is a new open source project that I&#8217;ve started on Codeplex. It will be a web application that will be used for tracking software bugs. Cricket.Net will be written in C# using HTML5, ASP.NET MVC 3, Entity Framework 4.1 Code First, StructureMap, and the Onion Architecture. This project will be an example application to demonstrate [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Summary</strong><br />
Cricket.Net is a new open source project that I&#8217;ve started on Codeplex. It will be a web application that will be used for tracking software bugs. Cricket.Net will be written in C# using HTML5, ASP.NET MVC 3, Entity Framework 4.1 Code First, StructureMap, and the Onion Architecture. This project will be an example application to demonstrate how to use these technologies together to build a web application from the ground up.</p>
<p>I&#8217;ll also be going through using Mercurial both on my system and pushing changes to the Codeplex site.</p>
<p>Cricket.Net Series:</p>
<ul>
<li>Part 1: Setting up the initial project</li>
<li><a href="http://www.cmjackson.net/2011/10/13/cricket-net-part-2-design-discussion/">Part 2: Design Discussion</a></li>
<li><a href="http://www.cmjackson.net/2011/12/13/cricket-net-part-3-unit-testing/">Part 3: Unit Testing</a></li>
</ul>
<p><strong>Prerequisites</strong><br />
To get started, I&#8217;ll be using Visual Studio 2010 SP1Rel and <a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=1491" target="_blank">ASP.NET MVC 3 Tools Update</a>. Later, I&#8217;ll be using <a href="http://www.microsoft.com/download/en/details.aspx?id=26825" target="_blank">Entity Framework 4.1 Update 1</a> so that I can use Code First. You can either download and install Entity Framework, or we&#8217;ll attempt to install this from the Nuget package first.</p>
<p><strong>Creating A New Project</strong><br />
Initially, I&#8217;m going to start with the basic MVC package created by Visual Studio. After this package is created, I&#8217;m going to create the Mercurial repository so that I can send the code to Codeplex.</p>
<ol>
<li>Open Visual Studio 2010.</li>
<li>Click the File menu, then New, Project.</li>
<li>In the New Project window, under Installed Templates, expand Visual C# and choose Web. Select the template called &#8220;ASP.NET MVC 3 Web Application.&#8221; The Name field will be the default name and namespace of your initial project, the Location will be the folder on your C:\ drive where to store your solution, and the Solution Name is the name of your solution folder (if you wish it to be different).<br />
<a href="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_01.png"><img class="alignnone size-medium wp-image-468" title="New Part window" src="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_01-300x207.png" alt="" width="300" height="207" /></a></li>
<li>After clicking OK, the New ASP.NET MVC 3 Project window pops up. I&#8217;m going to choose Internet Application so that the tooling will allow me to go ahead and create a Unit Test project also. I&#8217;m going to change the name of the Unit Test project to Cricket.UnitTests.<br />
<a href="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_02.png"><img class="alignnone size-medium wp-image-469" title="New ASP.NET MVC 3 Project" src="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_02-300x270.png" alt="" width="300" height="270" /></a></li>
<li>After Visual Studio finishes creating the project, it should look like the image below. The Internet Application template that we had chosen in the previous step has added some files that will may or may not use, but for now we&#8217;ll leave these in the solution and move on to creating the Mercurial repository.<br />
<a href="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_03.png"><img class="alignnone size-medium wp-image-470" title="Initial Solution Explorer" src="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_03-285x300.png" alt="" width="285" height="300" /></a></li>
</ol>
<p><strong>Setting up the Mercurial Repository</strong><br />
If you are unfamiliar with Mercurial, it is a source control application that is very fast and pretty easy to use. Before you can continue with this tutorial, you will need to install at least <a href="http://tortoisehg.bitbucket.org/" target="_blank">TortoiseHg</a> to manage the Mercurial repository from Windows Explorer.  If you&#8217;d also like to work with it from within Visual Studio, you will need <a href="http://visualhg.codeplex.com/" target="_blank">VisualHg</a>.  If you&#8217;d like to know more about what Mercurial can do, check out this <a href="http://tekpub.com/codeplex" target="_blank">video from tekpub.com</a>.</p>
<ol>
<li>If you still have your new solution open in Visual Studio, go to the File menu and choose Close Solution.</li>
<li>Next, browse to the folder where your solution folder is located. (In my case, I need to go to the C:\Users\cjackson\Documents\All Projects\ folder)</li>
<li>Right-click on the Cricket.Net folder and expand the TortoiseHg context menu and choose Create Repository Here.</li>
<li>TortoiseHg will display an Init window. Click the Create button to create the repository.</li>
<li>After the repository has been created, a green check mark icon will appear over the Cricket.Net folder icon.</li>
<li>Open the Cricket.Net folder and then edit the .hgignore file. This file will tell the repository to ignore certain files/folders that are used by Visual Studio and do not need to be version controlled. Paste the text below into the file and save it.</li>
</ol>
<pre class="brush: vb;"># use glob syntax
syntax: glob

*.obj
*.pdb
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
*.lib
*.sbr
*.scc
[Bb]in
[Dd]ebug*/
obj/
[Rr]elease*/
_ReSharper*/
[Tt]humbs.db
[Tt]est[Rr]esult*
[Bb]uild[Ll]og.*
*.[Pp]ublish.xml
*.resharper
</pre>
<p>Next, I&#8217;ll save the initial project into the Mercurial repository.</p>
<ol>
<li><span style="font-family: Consolas;">Return to the folder where your solution is stored. (C:\Users\cjackson\Documents\All Projects\ folder)</span></li>
<li>Right-click on the Cricket.Net folder and choose Hg Commit&#8230;</li>
<li>The Cricket.Net commit window will pop up. On the left pane, click the check box at the top to select all files then in the top-right pane, type in a comment for the commit. After you enter whatever comments you wish, click the Commit button to save the current state of the solution.<br />
<a href="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_05.png"><img class="alignnone size-medium wp-image-475" title="Commit" src="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_05-300x190.png" alt="" width="300" height="190" /></a></li>
<li>Next, for new untracked files, a window may pop up asking to add untracked files. Click Add.</li>
</ol>
<p>To save the current repository to Codeplex, follow these instructions:</p>
<ol>
<li>Return to the folder where your solution is stored. (C:\Users\cjackson\Documents\All Projects\ folder)</li>
<li>Right-click on Cricket.Net and expand the TortoiseHG context menu and choose Synchronize.</li>
<li>Under Remote Repository, change the drop down to HTTPS and enter the name of the repository so the URL looks like this (<a href="http://hg01.codeplex.com/cricket">http://hg01.codeplex.com/cricket</a>)</li>
<li>Click on the <a href="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_06.png"><img class="alignnone size-full wp-image-476" title="Push icon" src="http://www.cmjackson.net/wp-content/uploads/2011/10/part1_06.png" alt="" width="30" height="29" /></a> icon to push changes to Codeplex.</li>
<li>Enter your Codeplex username and password when prompted and the files will be uploaded to Codeplex.</li>
</ol>
<p>Visit the project site at: <a href="http://cricket.codeplex.com">http://cricket.codeplex.com</a>.<br />
Download the source code from this post at: <a href="http://cricket.codeplex.com/SourceControl/changeset/changes/1569d75e695b#">http://cricket.codeplex.com/SourceControl/changeset/changes/1569d75e695b#</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2011/10/12/cricket-net-part-1-setting-up-the-initial-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unknown Exceptions</title>
		<link>http://www.cmjackson.net/2011/03/02/unknown-exceptions/</link>
		<comments>http://www.cmjackson.net/2011/03/02/unknown-exceptions/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 18:03:03 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Exceptions]]></category>
		<category><![CDATA[Routing]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=438</guid>
		<description><![CDATA[When I build an ASP.NET MVC application, I like to add my own error handler and serve up some nicer error messages to the users of the systems.  I allow for unknown exceptions to be emailed to me along with a stack trace so I can attempt to track them down and resolve unhandled issues. [...]]]></description>
			<content:encoded><![CDATA[<p>When I build an ASP.NET MVC application, I like to add my own error handler and serve up some nicer error messages to the users of the systems.  I allow for unknown exceptions to be emailed to me along with a stack trace so I can attempt to track them down and resolve unhandled issues.</p>
<p>Today I came across something new.  There were two different files that the client browsers from certain users were trying to access on the server.</p>
<p>- /_vti_bin/owssvr.dll<br />
- /MSOffice/cltreq.asp</p>
<p>It appears that these are requests from a browser to look for web discussions on the site being accessed.  While this may be fine for a normal user&#8217;s browser, it is causing two exceptions to fire each time my application is being accessed.</p>
<p>To resolve this issue using ASP.NET MVC, I added the following code to the Global.asax.vb file at the beginning of the RegisterRoutes method:</p>
<pre class="brush: vb;">
routes.IgnoreRoute(&quot;_vti_bin/owssvr.dll&quot;)
routes.IgnoreRoute(&quot;MSOffice/cltreq.asp&quot;)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2011/03/02/unknown-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Visual Studio 2010 Remote Debugger with ASP.NET MVC</title>
		<link>http://www.cmjackson.net/2010/11/04/using-the-visual-studio-2010-remote-debugger-with-asp-net-mvc/</link>
		<comments>http://www.cmjackson.net/2010/11/04/using-the-visual-studio-2010-remote-debugger-with-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 19:20:53 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Remote Debugger]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=405</guid>
		<description><![CDATA[Visual Studio Remote Debugging Monitor To use the remote debugger with ASP.NET MVC applications, you first must run the Visual Studio Remote Debugger Monitor on the server or remote computer. There are two ways you can do this: - Copy the monitor&#8217;s files to the server or remote computer - Create a shared folder on [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Visual Studio Remote Debugging Monitor</strong></p>
<p>To use the remote debugger with ASP.NET MVC applications, you first must run the Visual Studio Remote Debugger Monitor on the server or remote computer.</p>
<p>There are two ways you can do this:</p>
<p>- Copy the monitor&#8217;s files to the server or remote computer<br />
- Create a shared folder on your developer client and run the monitor on the server from the share.</p>
<p>I will go through the shared folder method. Share out this folder:<br />
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Remote Debugger</p>
<p>If you server is running a 64-bit OS, use the x64 folder.  For the 32-bit OS, use the x86 folder.</p>
<p><strong>Setting up the server</strong></p>
<p>- Log into the server and navigate to the shared folder on your developer PC. <br />
- Go into the correct folder for your server&#8217;s OS (x86 or x64).<br />
- Run the msvsmon.exe file.  If your server&#8217;s OS is Windows 2008, you will need to right-click on the file and run as Administrator.<br />
- Open Tools -&gt; Permissions.  Make sure that your developer client user is listed here.  If not, add the user and click OK.  Click Yes to allow the user to debug.<br />
- Copy the name of the server (listed on the first line of the Visual Studio Remote Debugging Monitor).<br />
- Return to your developer client.</p>
<p><strong>Debugging remotely</strong></p>
<p>- Make sure the latest version of your application is published to the server (so your source code will be the same as the executed code).<br />
- From Visual Studio 2010, click Debug -&gt; Attach to process.<br />
- Change the value of the Qualifier field to the name of the server on the Visual Studio Remote Debugging Monitor and click Refresh.<br />
- Under the Available Processes, select &#8220;w3wp.exe&#8221; and click Attach.  If you do not see this process listed, then open a web browser and run your application.  After your application has loaded, click the Refresh button and you should see the process.</p>
<p>* If you receive any error messages, you may need to:<br />
- Click Build -&gt; Clean Solution<br />
- Click Build -&gt; Rebuild Solution<br />
- Republish your application to the server<br />
- Click Debug -&gt; Attach To Process</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2010/11/04/using-the-visual-studio-2010-remote-debugger-with-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Setting up Structure Map</title>
		<link>http://www.cmjackson.net/2010/05/14/setting-up-structure-map/</link>
		<comments>http://www.cmjackson.net/2010/05/14/setting-up-structure-map/#comments</comments>
		<pubDate>Fri, 14 May 2010 14:34:20 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[StructureMap]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=388</guid>
		<description><![CDATA[StructureMap If you haven&#8217;t heard about dependency injection, it is something you should definitely look into. It can save tons of time when coding. StructureMap is a dependency injection framework that makes it easy to create new instances of objects and even cache an instance of an object so various references to the object use the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>StructureMap<br />
</strong>If you haven&#8217;t heard about dependency injection, it is something you should definitely look into. It can save tons of time when coding.</p>
<p>StructureMap is a dependency injection framework that makes it easy to create new instances of objects and even cache an instance of an object so various references to the object use the same instance. This is very useful with objects such as database connections.</p>
<p>You can download the library from <a href="http://structuremap.github.com/structuremap/index.html">the StructureMap Home Page</a>. The example used in this post is using StructureMap 2.6.1.  I&#8217;m also using Visual Basic.  I had a tough time finding information on how to use StructureMap with Visual Basic, so hopefully, this will help someone else.</p>
<p><strong>Setting Up MVC<br />
</strong>When using StructureMap with ASP.NET MVC 1.0, I&#8217;ve found it works best if a folder is created in each project; Main, Data, and Service; where the StructureMap files are stored. This keeps them organized and makes them easy to find as you need to update them. A reference to the StructureMap DLL will need to be added to each project as well.</p>
<p>In the main project&#8217;s StructureMap folder, the following files are needed:</p>
<p><strong>StructureMapControllerFactory</strong></p>
<pre class="brush: vb;">
Imports System.Web.Mvc
Imports StructureMap

Public Class StructureMapControllerFactory
    Inherits DefaultControllerFactory

    Protected Overrides Function GetControllerInstance(ByVal controllerType As System.Type) As System.Web.Mvc.IController

        Return ObjectFactory.GetInstance(controllerType)

    End Function

End Class</pre>
<p>This class sets up a factory class to get an instance of the StructureMap factory. It will be used to replace MVC&#8217;s default controller factory so that StructureMap will be in charge of creating our controllers.</p>
<p><strong>BootStrapper</strong></p>
<pre class="brush: vb;">
Imports StructureMap
Imports YourProject.Data
Imports YourProject.Services

Public Class BootStrapper

    Public Shared Sub ConfigureStructureMap()

        ObjectFactory.Initialize(AddressOf StructureMapRegistry)

    End Sub

    Private Shared Sub StructureMapRegistry(ByVal x As IInitializationExpression)

        x.AddRegistry(New MainRegistry())
        x.AddRegistry(New DataRegistry( _ ConfigurationManager.ConnectionStrings(&quot;iSeries&quot;).ConnectionString, _ ConfigurationManager.ConnectionStrings(&quot;Interbase&quot;).ConnectionString))
        x.AddRegistry(New ServiceRegistry())
        x.Scan(AddressOf StructureMapScanner)

    End Sub

    Private Shared Sub StructureMapScanner(ByVal scanner As StructureMap.Graph.IAssemblyScanner)

        scanner.Assembly(&quot;YourProjectNamespace&quot;)
        scanner.Assembly(&quot;YourProjectNamespace.Data&quot;)
        scanner.Assembly(&quot;YourProjectNamespace.Services&quot;)
        scanner.WithDefaultConventions()

    End Sub
End Class</pre>
<p>This class is where StructureMap is configured. Within the StructureMapRegistry method, each AddRegistry call is made to include each of our project&#8217;s registry files, which have yet to be created. We will get to that in a moment, but notice that the DataRegistry is accepting values for connection strings. This is how information can be passed into a class being created by StructureMap when you would like to keep the configuration settings within the Web.config file.</p>
<p>Also, within the StructureMapScanner method, an entry needs to be made to scan each project&#8217;s namespace.</p>
<p><strong>MainRegistry</strong></p>
<pre class="brush: vb;">
Imports DCS.Data
Imports StructureMap.Configuration.DSL

Public Class MainRegistry
    Inherits Registry

    Public Sub New()

        [For](Of IWebContext)() _
            .Use(Of WebContext)()

    End Sub

End Class</pre>
<p>Each project will have its own registry file where you can specify that Interface-A should create an instance of Class-A. In the example above, I want StructureMap to create an instance of WebContext (from the main project) when it comes across a reference to IWebContext. </p>
<p>In the Data project&#8217;s StructureMap folder you will need:</p>
<p><strong>DataRegistry</strong></p>
<pre class="brush: vb;">
Imports StructureMap.Configuration.DSL
Imports Spartan.DAO.Database

Public Class DataRegistry
    Inherits Registry

    Public Sub New(ByVal iSeriesConnectionString As String, ByVal interbaseConnectionString As String)

    'Data Connections.
    [For](Of YourDataContext)() _
        .HybridHttpOrThreadLocalScoped _
        .Use(Function() New YourDataContext())

    [For](Of DB2Connection)() _
        .HybridHttpOrThreadLocalScoped _
        .Use(Function() New DB2Connection(iSeriesConnectionString))

    [For](Of InterbaseConnection)() _
        .HybridHttpOrThreadLocalScoped _
        .Use(Function() New InterbaseConnection(interbaseConnectionString))

    'Repositories.
    [For](Of IShiftRepository)() _
        .Use(Of ShiftRepository)()

    End Sub

End Class</pre>
<p>The DataRegistry is interesting because we are passing in two connection strings from the Web.config file. The first data connection is for Microsoft SQL, the second for DB2 and the third for Interbase. The second and third are using the DB2Connection  and InterbaseConnection classes which are home grown database connection class that I wrote.  All three of these database connections are being cached by using the .HybridHttpOrThreadLocalScoped property. Using this will make the database cached instance work for both your live program and your unit testing.</p>
<p>The entry under repositories is what all remaining entries would look like within the registry class. Since the data project contains our repositories, they would all be listed here.</p>
<p>And, in the Service project&#8217;s StructureMap folder you will need:</p>
<p><strong>ServiceRegistry</strong></p>
<pre class="brush: vb;">
Imports StructureMap.Configuration.DSL

Public Class ServiceRegistry
    Inherits Registry

    Public Sub New()

        [For](Of IShiftService)() _
        .Use(Of ShiftService)()

    End Sub

End Class</pre>
<p>The service registry is similar to that of the main project. All service classes found in the service project would be listed here.</p>
<p><strong>Changes to the Global.asax</strong></p>
<p>The last thing to do is setup the Global.asax file to load StructureMap.  Make the following changes to the Application_Start method:</p>
<pre class="brush: vb;">
Sub Application_Start()

    RegisterRoutes(RouteTable.Routes)

    'StructureMap
    BootStrapper.ConfigureStructureMap()
    ControllerBuilder.Current.SetControllerFactory(New StructureMapControllerFactory())

End Sub</pre>
<p>Now, the default controller factory used by MVC will be overridden by our StructureMapControllerFactory. When a controller is created, it will now use StructureMap.</p>
<p>So, how do you use this when creating a class? This is the easy part.</p>
<p>StructureMap will use the greediest constructor from your controller, meaning, if you have two constructors, the one with the most parameters will be used. Each parameter references an Interface and sets a class variable for the object.  StructureMap uses the registry classes that we setup to map an interface to a real object.</p>
<p><strong>Example Controller</strong></p>
<pre class="brush: vb;">
Imports YourProject.Data
Imports YourProject.Services
Imports StructureMap

Public Class ExampleController
    Inherits System.Web.Mvc.Controller

    Private _shiftService As IShiftService
    Private _webContext As IWebContext

    Public Sub New( _
        ByVal shiftService As IShiftService, _
        ByVal webContext As IWebContext)

        _shiftService = shiftService
        _webContext = webContext

        'Initialize service classes.
        _shiftSummaryService.Initialize(New ModelStateWrapper(Me.ModelState))

    End Sub

    ...</pre>
<p>All that you need to do is create a constructor, pass in all the interface references you need for the controller, then store them in a class variable. If you need to use the ModelState for validation within your service class, the best way I&#8217;ve found to do this is use an Initialize function in your service class to pass in the ModelState. This is because the ModelState is not yet created by MVC when the service classes are created by StructureMap.</p>
<p>When StructureMap creates the instance of the ShiftService, it will look at the greediest constructor from that class to create instances for any required parameters. This continues for all classes that are referenced.</p>
<p>Once the solution has been configured to use StructureMap, the only thing you&#8217;ll need to maintain will be the registry files as you add new classes and interfaces to your project. Don&#8217;t forget to add a registry entry or you will recieve an exception.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2010/05/14/setting-up-structure-map/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC &#8211; Organizing your solution</title>
		<link>http://www.cmjackson.net/2010/02/04/asp-net-mvc-organizing-your-solution/</link>
		<comments>http://www.cmjackson.net/2010/02/04/asp-net-mvc-organizing-your-solution/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 14:16:25 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[organization]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=379</guid>
		<description><![CDATA[Keeping your project files organized will help you navigate through your projects and help you find what you are looking for to make changes faster. Here are some tips that I use to help keep my ASP.NET MVC solutions organized: Use multiple projects to separate sections of the program. Use folders to group interfaces, classes, and factories [...]]]></description>
			<content:encoded><![CDATA[<p>Keeping your project files organized will help you navigate through your projects and help you find what you are looking for to make changes faster.</p>
<p>Here are some tips that I use to help keep my ASP.NET MVC solutions organized:</p>
<ol>
<li>Use multiple projects to separate sections of the program.</li>
<li>Use folders to group interfaces, classes, and factories that deal with an object.</li>
<li>If objects can be used by other programs, put them in their own class library project.</li>
</ol>
<p><strong>Option 1</strong><br />
When beginning a new program, I usually start by creating an ASP.NET MVC solution with 4 projects:</p>
<ul>
<li><span style="text-decoration: underline;">The main project</span> &#8211; which contains the MVC components of the application such as Controllers, Views, CSS, and JavaScript files.</li>
<li><span style="text-decoration: underline;">The unit testing project</span> &#8211; which contains all of the requirements for the application along with any fake repositories used for testing.</li>
<li><span style="text-decoration: underline;">The data project</span> &#8211; which contains the repositories and domain objects used by the application.</li>
<li><span style="text-decoration: underline;">The services project</span> &#8211; which contains the service objects that are the middle-man between the Controller and the Repository.</li>
</ul>
<p><strong>Option 2</strong><br />
Folders are used within the projects to further organize the code files within. The data project could have a domain object called Operation.  Domain objects are placed in a folder with the same name as the object.  Interfaces, Repositories, and Factories that deal with the object are also placed in the domain object folder.</p>
<p>The service project is organized similar to the data project.</p>
<p>The unit test project is slightly modified from the default to create a folder which contains all fake repository objects and another folder to contain requirement tests. Depending on the detail of unit testing you wish to utilize, you may have unit tests that verify application requirements and/or unit tests that further verify other parts your code.</p>
<p>In my opinion, you can write application requirements that detail exactly what the program should do and as long as you unit test these requirements, you don&#8217;t need to waste time trying to unit test 100% of your program. If a bug is found later, it will most likely be because it was not an application requirement. Then, add a new requirement, write a unit test, and make the application pass the new test.</p>
<p><strong>Option 3</strong><br />
Where I work, we have various databases that we need to communicate with. We wanted a way to use these databases the same way every time without having to remember all of the different objects and names that needed to be used by each. So, I developed a parent wrapper class around the basic database functionality and then individual wrappers around each database object that inherited from the parent wrapper. Now, we can call up any of the database connections and work with them in exactly the same way, the only difference between them is the call to the factory when creating the instance.</p>
<p>These database wrappers were added to their own separate project so that in future applications, we could continue to reuse them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2010/02/04/asp-net-mvc-organizing-your-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring IIS 6 and ASP.NET MVC</title>
		<link>http://www.cmjackson.net/2010/01/28/configuring-iis-6-and-asp-net-mvc/</link>
		<comments>http://www.cmjackson.net/2010/01/28/configuring-iis-6-and-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 14:00:09 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[IIS 6.0]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=363</guid>
		<description><![CDATA[By default, IIS 6 does not work with ASP.NET MVC and needs to be configured to use wild-card mapping to get MVC&#8217;s routing and clean URLs to work correctly. Unfortunately, IIS 6 does take a performance hit because all requests are processed by ASP.NET. Static files, such as images, CSS, and JavaScript are processed as [...]]]></description>
			<content:encoded><![CDATA[<p>By default, IIS 6 does not work with ASP.NET MVC and needs to be configured to use wild-card mapping to get MVC&#8217;s routing and clean URLs to work correctly. Unfortunately, IIS 6 does take a performance hit because all requests are processed by ASP.NET. Static files, such as images, CSS, and JavaScript are processed as a dynamic page instead of a static one.</p>
<p><strong>Install ASP.NET MVC</strong><br />
Follow the first two steps of the instructions for <a href="http://www.cmjackson.net/2010/01/15/installing-asp-net-mvc/">installing ASP.NET MVC</a>. The third step can be ignored since Visual Studio will not be installed on the server.</p>
<p><strong>Configuring ASP.NET 2.0</strong><br />
First thing to do is open the IIS Manager -&gt;expand your server -&gt;Web Service Extensions folder. Right-click on the white space under the list of Web Service Extensions and select to Add a new Web service extension&#8230;</p>
<p>The New Web Service Extension window will pop open. Enter &#8220;ASP.NET v2.0.50727&#8243; as the Extension Name and click the Add button.  Browse to the C:\Windows\Microsoft.Net\Framework\v2.0.50727 folder and select the aspnet_isapi.dll file. Make sure to check the &#8220;Set extension status is Allowed&#8221; button before clicking OK.</p>
<p>This will allow your programs to run ASP.NET 2.0, 3.0, and 3.5 versions of the .NET framework.</p>
<p><strong>Configuring Your Web Application</strong><br />
The next thing to do is open the properties of the Web Site where your web application is. Select the ASP.NET tab and select 2.0.50717 in the ASP.NET version drop down box.</p>
<p>Next, click on the Home Directory tab. Click on the Configuration button. Under the Wild-card application maps area, click the Insert button. Browse to the C:\Windows\Microsoft.Net\Framework\v2.0.50727 folder and select the aspnet_isapi.dll file. Uncheck the &#8220;Verify that file exists&#8221; before clicking OK. Save your changes and your site should now be able to run ASP.NET MVC and use the routes setup by your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2010/01/28/configuring-iis-6-and-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scheduling A Task In A Web Application On A Windows Server</title>
		<link>http://www.cmjackson.net/2010/01/19/scheduling-a-task-in-a-web-application-on-a-windows-server/</link>
		<comments>http://www.cmjackson.net/2010/01/19/scheduling-a-task-in-a-web-application-on-a-windows-server/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:00:43 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[scheduling]]></category>
		<category><![CDATA[web application]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=310</guid>
		<description><![CDATA[When writting web applications, there may be times when you would like to perform some task automatically at the same time or every X number of hours. Web applications only execute their code when a request is made from a client&#8217;s browser. Because of this, scheduled tasks within the web application will not work. There are [...]]]></description>
			<content:encoded><![CDATA[<p>When writting web applications, there may be times when you would like to perform some task automatically at the same time or every X number of hours. Web applications only execute their code when a request is made from a client&#8217;s browser. Because of this, scheduled tasks within the web application will not work.</p>
<p>There are a few different options:</p>
<ol>
<li>Build a separate Windows Service application that can connect to the assemblies your web application uses to execute the scheduled task.</li>
<li>Build a separate Windows application that communicates with a web service that your web application also uses to perform the scheduled task.</li>
<li>Use the Windows Scheduler to call the URL of the action to perform the task.</li>
</ol>
<p>The first option might sound good at first, but creating a separate program that talks to your web application&#8217;s library files is a bad idea. Maintenance will become a problem as you change your web application. Since the code is in two places, unit testing will not tell you that the class library you just changed has now broken your scheduled tasks in your windows service. </p>
<p>The second option is slightly better, but you still may have issues with changing your class library.</p>
<p>The third option is the one that I will show you how to configure. We will setup a VBS script that will perform a call to any web address we pass to it. Then, we&#8217;ll setup a batch file that calls the VBS script and passes in one or more URLs to execute. And finally, we&#8217;ll go through using the Windows Scheduler to create the scheduled task when the batch file should execute.</p>
<p>The primary advantage to this method is that you get to keep all of your code together in your web application. You simply setup an action that performs whatever task you wish to schedule and make sure that action is callable from an anonymous user.</p>
<p><strong>WebRequest.vbs</strong><br />
You may copy the following code and paste into a text file. Then, rename the file to WebRequest.vbs. The script basically takes an argument that is passed into it as the URL. The HTTP object is setup and then the URL is called using a GET request. Then, the returned status is checked to see if the request was successful or not.</p>
<pre class="brush: vb;">
url = WScript.Arguments.Item(0)
'WScript.echo url

set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
set http = CreateObject(&quot;Microsoft.XmlHttp&quot;)

http.open &quot;GET&quot;, url, FALSE
http.send &quot;&quot;

if (http.Status = 200) then

    WScript.echo &quot;Request successful.&quot;

else

    WScript.echo &quot;Error: &quot; &amp; http.Status

end if

set WshShell = nothing
set http = nothing
</pre>
<p><strong>The Batch File</strong><br />
Calling the WebRequest.vbs file from a batch file is very easy. Simply create a new text file, calling it whatever you&#8217;d like, and paste in the following line of text. Rename the file to .BAT when finished.</p>
<pre class="brush: plain;">
cscript WebRequest.vbs &quot;http://www.domain.com/controller/action&quot;
</pre>
<p><strong>Scheduling The Task</strong><br />
From your Windows server, open the Control Panel and then open the Scheduled Tasks item. Next, click on Add Scheduled Task. Choose any application to schedule.  This will be changed later on. Configure how often you wish the schedule to run and enter a user name and password to run the schedule as. This users should have access to running the web browser from the server.</p>
<p>After your new scheduled task has been created, open it. In the Run text box, type in the full path to your batch file. Then, in the Start In text box, type in the full path without the batch file name. You can also adjust your scheduled time from within here. Click OK to save the changes and your scheduled task should be ready.</p>
<p>You can test the Windows Scheduler by setting the scheduled time to a minute or two in the future and then waiting for it to execute. If you just wish to test your action, or manually run it, you can simply run the batch file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2010/01/19/scheduling-a-task-in-a-web-application-on-a-windows-server/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Installing ASP.NET MVC</title>
		<link>http://www.cmjackson.net/2010/01/15/installing-asp-net-mvc/</link>
		<comments>http://www.cmjackson.net/2010/01/15/installing-asp-net-mvc/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 14:00:38 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=297</guid>
		<description><![CDATA[Here are the steps to install into Visual Studio 2008: Download ASP.NET MVC 1.0 from Microsoft&#8217;s website. Make sure to download the MSI file and the source code if you would like to see how it works. Install the AspNetMVC1.msi file. Open Visual Studio 2008 and go to: File -&#62; New -&#62; Project Under Project Types, select [...]]]></description>
			<content:encoded><![CDATA[<p>Here are the steps to install into Visual Studio 2008:</p>
<ol>
<li>Download <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=53289097-73ce-43bf-b6a6-35e00103cb4b&amp;displaylang=en">ASP.NET MVC 1.0</a> from Microsoft&#8217;s website. Make sure to download the MSI file and the source code if you would like to see how it works.</li>
<li>Install the AspNetMVC1.msi file.<a href="http://www.cmjackson.net/wp-content/uploads/2007/12/cd-case.png"></a></li>
<li>Open Visual Studio 2008 and go to:
<ol>
<li>File -&gt; New -&gt; Project</li>
<li>Under Project Types, select Web under either Visual Basic or C#</li>
<li>Under Templates, select ASP.NET MVC Web Application</li>
<li>Give your application a name and change its location if you wish</li>
</ol>
</li>
</ol>
<p>That&#8217;s it! Upon creating a new web application, the default MVC application will open.</p>
<p><strong>Note:</strong><br />
ASP.NET MVC should also work using the free development tool from Microsoft, <a href="http://www.microsoft.com/express/vwd/">Visual Web Designer 2008</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2010/01/15/installing-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

