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

<channel>
	<title>Chris Fulstow &#187; asp.net</title>
	<atom:link href="http://chrisfulstow.com/category/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisfulstow.com</link>
	<description>ASP.NET Tech Lead and Web Developer</description>
	<lastBuildDate>Sat, 05 Jun 2010 01:32:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>.NET Framework 3.5 Reference Poster</title>
		<link>http://chrisfulstow.com/net-framework-35-reference-poster/</link>
		<comments>http://chrisfulstow.com/net-framework-35-reference-poster/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 06:45:14 +0000</pubDate>
		<dc:creator>Chris Fulstow</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://3poundmass.wordpress.com/?p=97</guid>
		<description><![CDATA[This slick .NET 3.5 reference poster is available as a free download from MSDN.  It&#8217;s got the most commonly used types and namespaces in the framework.  A great quick reference for any .NET developer&#8217;s office wall:

As it&#8217;s getting progressively harder to keep up with .NET&#8217;s continutally expanding scope, this poster is a handy reminder <a href="http://chrisfulstow.com/net-framework-35-reference-poster/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>This slick <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7b645f3a-6d22-4548-a0d8-c2a27e1917f8&amp;DisplayLang=en">.NET 3.5 reference poster</a> is available as a <strong>free download</strong> from MSDN.  It&#8217;s got the most commonly used <strong>types and namespaces</strong> in the framework.  A great quick reference for any .NET developer&#8217;s office wall:</p>
<p><a title=".NET 3.5 Reference Poster" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7b645f3a-6d22-4548-a0d8-c2a27e1917f8&amp;DisplayLang=en"><img style="border: 1px solid #dddddd;" src="http://chrisfulstow.com/wp-content/uploads/2007/12/dotnet-poster.png" alt=".NET 3.5 Poster" /></a></p>
<p>As it&#8217;s getting progressively harder to keep up with <a href="http://asp.net/downloads/3.5-extensions/">.NET&#8217;s continutally expanding scope</a>, this poster is a handy reminder of what&#8217;s included.  It shows which classes were added in .NET 3.0, and which in .NET 3.5.</p>
<p>There&#8217;s a broad cross-section across all areas of the .NET Framework:</p>
<ul>
<li>ASP.NET</li>
<li>WinForms and WPF</li>
<li>Communications and Workflow</li>
<li>Data, XML and LINQ</li>
<li>Fundamentals</li>
</ul>
<p><span style="text-decoration: underline;"><strong>Printing</strong></span></p>
<p>The hi-res version is Microsoft <a href="http://en.wikipedia.org/wiki/XML_Paper_Specification">XPS</a> format, so if you&#8217;re not using Vista or Office 2007 then you might want the <a href="http://www.microsoft.com/whdc/xps/viewxps.mspx">Microsoft XPS Viewer</a>. Also, for &#8216;easy printing&#8217;, there&#8217;s a 16 page 4&#215;4 version, but remember: &#8217;some assembly is required if you choose this print method&#8217;, so remember to ask an adult for help with the scissors.</p>
<p>My local print shop printed and laminated the PDF version onto A1, which is easily hi-res enough and looks great.</p>
<p><span style="text-decoration: underline;"><strong>Other .NET Reference Posters</strong></span></p>
<p>There are a few other reference posters on MSDN, in particular I like the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=811d8ad6-8d48-4684-b08c-686462d58a56&amp;DisplayLang=en">Silverlight Developer Reference</a>, and <strong>keyboard shortcuts for Visual Studio 2008</strong>, available for both <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=e5f902a8-5bb5-4cc6-907e-472809749973&amp;DisplayLang=en">C# </a>and <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=255b8cf1-f6bd-4b55-bb42-dd1a69315833&amp;DisplayLang=en">Visual Basic</a>.</p>
<p>(Thanks to <a href="http://blogs.msdn.com/cbowen/archive/2007/12/09/got-tech-posters.aspx">Chris Bowen</a> for the tip off.)</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisfulstow.com/net-framework-35-reference-poster/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Server 2008 will have IntelliSense</title>
		<link>http://chrisfulstow.com/sql-server-2008-will-have-intellisense/</link>
		<comments>http://chrisfulstow.com/sql-server-2008-will-have-intellisense/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 02:59:36 +0000</pubDate>
		<dc:creator>Chris Fulstow</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[sql server 2008]]></category>

		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/11/30/sql-server-2008-will-have-intellisense/</guid>
		<description><![CDATA[With so many exciting new features in Visual Studio 2008 to explore, I haven&#8217;t had much time to look at the preview releases of SQL Server 2008 (aka Katmai).  The last I heard, there wouldn&#8217;t be that many new goodies for developers, mainly features for DBAs and BI analysts with a few performance optimisations <a href="http://chrisfulstow.com/sql-server-2008-will-have-intellisense/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>With so many exciting <a href="http://weblogs.asp.net/scottgu/archive/2007/11/19/visual-studio-2008-and-net-3-5-released.aspx">new features in Visual Studio 2008</a> to explore, I haven&#8217;t had much time to look at the preview releases of <strong>SQL Server 2008</strong> (aka <em>Katmai</em>).  The last I heard, there wouldn&#8217;t be that many new goodies for developers, mainly features for <strong>DBAs</strong> and <strong>BI analysts</strong> with a few performance optimisations thrown in.</p>
<p>The last upgrade, SQL Server 2000 to 2005, was a huge leap forward for developers and added <strong>significant advances</strong> like CLR integration, SQL Server Management Objects (SMO), Integration Services (SSIS) and a native XML data type; as well as T-SQL enhancements like Common Table Expressions (CTEs), structured error handling with try/catch, pivot, apply, top(n) and row_number.</p>
<p>I was surprised to see how much new stuff is packed into the latest <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=3BF4C5CA-B905-4EBC-8901-1D4C1D1DA884&amp;displaylang=en">SQL Server 2008 CTP release</a>, even, finally, <strong>IntelliSense for Management Studio</strong>, which was much anticipated but conspicuously absent from SQL 2005:</p>
<p><a title="SQL Server 2008 IntelliSense" href="http://chrisfulstow.com/wp-content/uploads/2007/11/sql2008-intellisense.png"><img src="http://chrisfulstow.com/wp-content/uploads/2007/11/sql2008-intellisense.png" alt="SQL Server 2008 IntelliSense" /></a></p>
<p>Also notice the new <strong>collapsible code regions</strong>, just like you get in Visual Studio.  Editing T-SQL has never been such fun!  Although, you have to feel a bit sorry for RedGate, whose <a href="http://www.red-gate.com/products/sql_prompt/index.htm">SQL Prompt</a> plug-in has been filling the auto-completion gap for the last few years.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisfulstow.com/sql-server-2008-will-have-intellisense/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Finding orphaned stored procedures and user-defined functions in SQL Server</title>
		<link>http://chrisfulstow.com/finding-orphaned-stored-procedures-and-user-defined-functions-in-sql-server/</link>
		<comments>http://chrisfulstow.com/finding-orphaned-stored-procedures-and-user-defined-functions-in-sql-server/#comments</comments>
		<pubDate>Thu, 22 Nov 2007 02:49:14 +0000</pubDate>
		<dc:creator>Chris Fulstow</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/11/22/finding-orphaned-stored-procedures-and-user-defined-functions-in-sql-server/</guid>
		<description><![CDATA[I&#8217;m currently working on a group of ASP.NET 2.0 websites deployed across about thirty countries.  The local flagship site runs on an upgraded version of the original code, and I&#8217;m now in the process of bringing all the other sites onto the new improved version.
Over time, new features have been introduced to the site, <a href="http://chrisfulstow.com/finding-orphaned-stored-procedures-and-user-defined-functions-in-sql-server/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a group of <strong>ASP.NET 2.0 websites</strong> deployed across about <strong>thirty countries</strong>.  The local flagship site runs on an upgraded version of the original code, and I&#8217;m now in the process of bringing all the other sites onto the new improved version.</p>
<p>Over time, new features have been introduced to the site, and old ones removed.  Consequently the <strong>SQL Server database</strong> now contains many <strong>redundant tables</strong> that aren&#8217;t used.  So, before cascading out the current schema to the other countries, it&#8217;s time for a clean up.</p>
<p>I managed to identify about 60 tables that aren&#8217;t used by the application and can safely can be dropped or archived.  However, I&#8217;m now left with <strong>hundreds of stored procedures</strong> (SPs) and user-defined functions (UDFs) that were associated with these tables, which can also be removed.</p>
<p>The problem was how to find these <strong>orphaned objects</strong>.  My first approach was a small .NET <strong>console application </strong>which uses <a href="http://technet.microsoft.com/en-us/library/ms162169.aspx">SQL Server Management Objects</a> (SMO).  It loops through all SPs and UDFs and finds any that have <strong>no dependencies</strong>.</p>
<pre class="brush: csharp;">

public List&lt;string&gt; FindOrphans()
{
   Server server = new Server(&quot;.&quot;);
   Database db = server.Databases[&quot;MyDatabase&quot;];
   List&lt;string&gt; orphans = new List&lt;string&gt;();

   // get list of SPs
   UrnCollection urns = new UrnCollection();
   foreach (StoredProcedure sp in db.StoredProcedures)
   {
      // exclude these objects
      if (sp.IsSystemObject) continue;
      if (sp.Name.StartsWith(&quot;aspnet_&quot;)) continue;
      urns.Add(sp.Urn);
   }

   // get dependencies
   DependencyWalker dw = new DependencyWalker(server);
   DependencyTree tree = dw.DiscoverDependencies(urns, true);

   // find all objects without any dependencies
   DependencyTreeNode node = tree.FirstChild;
   do {
      if (!node.HasChildNodes)
      {
         string name = new Urn(node.Urn).GetAttribute(&quot;Name&quot;);
         orphans.Add(name);
      }
      node = node.NextSibling;
   } while (node != null);

   return orphans;
}
</pre>
<p>This works fine, and helped satisfy my current obsession with SMO.  But it&#8217;s a bit awkward, and not easily <strong>portable or modifiable</strong>, to have this pure database operation wrapped up in an executable.  So I looked into doing the same thing with just a <strong>TSQL query</strong>.</p>
<pre class="brush: sql;">
-- Find all SPs and UDFs have no dependencies
select
    object_name(obj.[object_id]) as [orphaned_object_name],
    obj.type_desc as [object_type],
    'DROP ' +
    case obj.type_desc
        when 'SQL_STORED_PROCEDURE' then 'PROCEDURE'
        else 'FUNCTION'
    end
    + ' [' + object_name(obj.[object_id]) + ']'
from
    sys.objects obj
    left join (select distinct [object_id] from sys.sql_dependencies) dep
        on obj.object_id = dep.object_id
where
    type_desc in
        ('SQL_STORED_PROCEDURE','SQL_SCALAR_FUNCTION','SQL_TABLE_VALUED_FUNCTION')
    and object_name(obj.[object_id]) not like 'aspnet_%'
    and dep.object_id is null
order by
    obj.type_desc, object_name(obj.[object_id])
</pre>
<p>The query works by checking for dependencies in the <strong>catalog view</strong> <a href="http://msdn2.microsoft.com/en-us/library/ms174402.aspx">sys.sql_dependencies</a>.  This, I think, is a neater solution.  I also included an <strong>auto-generated column</strong> that writes the SQL drop the SP or UDF, which I copied and executed.</p>
<p>Now, if only I could find a quick way to check for dependencies between my application&#8217;s <strong>data access layer </strong>and the database&#8230;</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2f3poundmass.wordpress.com%2f2007%2f11%2f22%2ffinding-orphaned-stored-procedures-and-user-defined-functions-in-sql-server%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2f3poundmass.wordpress.com%2f2007%2f11%2f22%2ffinding-orphaned-stored-procedures-and-user-defined-functions-in-sql-server%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://chrisfulstow.com/finding-orphaned-stored-procedures-and-user-defined-functions-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Reading other people&#039;s .NET code</title>
		<link>http://chrisfulstow.com/reading-other-peoples-net-code/</link>
		<comments>http://chrisfulstow.com/reading-other-peoples-net-code/#comments</comments>
		<pubDate>Mon, 27 Aug 2007 08:38:35 +0000</pubDate>
		<dc:creator>Chris Fulstow</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[codeplex]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/27/reading-other-peoples-net-code/</guid>
		<description><![CDATA[One thing that makes HTML easy to learn is the abundance of examples. You can go to any old website and view the source to see how it&#8217;s put together, or look through templates on a site like Open Source Web Design or Open Source Templates. It&#8217;s easy find examples of good (and bad) practice.
Scott Hanselman&#8217;s <a href="http://chrisfulstow.com/reading-other-peoples-net-code/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>One thing that makes HTML easy to learn is the abundance of examples. You can go to any old website and view the source to see how it&#8217;s put together, or look through templates on a site like <a href="http://www.oswd.org/">Open Source Web Design</a> or <a href="http://opensourcetemplates.org/">Open Source Templates</a>. It&#8217;s easy find examples of good (and bad) practice.</p>
<p>Scott Hanselman&#8217;s article <a href="http://www.hanselman.com/blog/ReadingToBeABetterDeveloperTheCoding4FunDevKit.aspx">Reading to Be a Better Developer</a> got me wondering why we don&#8217;t do this more with <strong>.NET code</strong>, and the problem for me seems to be finding good code examples. Scott recommends looking at the <a href="http://www.codeplex.com/C4FDevKit">Coding4Fun Developer Kit</a>, but I wanted something more specific to web development.</p>
<p>So here are a few places I found ASP.NET source code that&#8217;s worth studying and learning from.</p>
<p><strong>Microsoft Enterprise Library</strong></p>
<p>A great place to start is the <a href="http://msdn2.microsoft.com/en-us/practices/bb190359.aspx">application blocks</a> in Microsoft&#8217;s <a href="http://www.microsoft.com/downloads/details.aspx?familyid=4c557c63-708f-4280-8f0c-637481c31718&amp;displaylang=en">Enterprise Library</a>. These are application service components designed to follow Microsoft best practices and include modules for caching, cryptography, data access, exception handling, logging, policy injection, security and validation.</p>
<p><strong>Website Starter Kits</strong></p>
<p>Another good place to look is the <a href="http://www.asp.net/downloads/starter-kits/">ASP.NET Starter Kit Websites</a>, a collection of working ASP.NET demos that can be examined or built on. They cover DotNetNuke, e-commerce with PayPal, blogging, project time management, media library and plenty more.</p>
<p><strong>Codeplex</strong></p>
<p>Lastly <a href="http://www.codeplex.com/">Codeplex</a>, Microsoft&#8217;s open source project hosting site. There&#8217;s so much goodness here it&#8217;s hard know where to start, so try browsing the most popular or active projects to start. Here are the top ten that caught my eye:</p>
<ul>
<li><span><a href="http://www.codeplex.com/blogengine">BlogEngine.NET</a><br />
Full featured blog engine targeted at .NET developers. It is light weight and very simple to modify and extend.</span></li>
<li><a href="http://www.codeplex.com/umbraco">Umbraco</a><br />
Simple, flexible and friendly ASP.NET CMS</li>
<li><a href="http://www.codeplex.com/DinnerNow">DinnerNow</a><br />
Sample marketplace application designed to demonstrate how you can develop a connected application using IIS7, ASP.NET Ajax Extensions, Linq, WCF, WF, WPF, Powershell, and the .NET Compact Framework.</li>
<li><a href="http://www.codeplex.com/CKS">Community Kit for SharePoint</a><br />
<span>Set of best practices, templates, Web Parts, tools, and source code for creating a community website based on SharePoint.<br />
</span></li>
<li><span><a href="http://www.codeplex.com/FacebookToolkit">Facebook Developer Toolkit</a> and <a href="http://www.codeplex.com/FacebookNET">Facebook.NET</a><br />
.NET wrappers and libraries for the Facebook API.</span></li>
<li><span><a href="http://www.codeplex.com/DbEntry">DbEntry.Net</a><br />
Lightweight, high performance Object Relational Mapping (ORM) database access compnent for .NET 2.0.</span></li>
<li><span><a href="http://www.codeplex.com/publicdomain">PublicDomain</a><br />
</span><span>.NET</span><span> packages for time zone support, logging, dynamic code evaluation, GAC API, unzipping, RSS, Atom, OPML, screen scraping, and utilities for strings, arrays and cryptography.</span></li>
<li><span><a href="http://www.codeplex.com/ASPNETRSSToolkit">ASP.NET RSS Toolkit</a><br />
Gives ASP.NET applications the ability to consume and publish to RSS feeds.</span></li>
<li><a href="http://www.codeplex.com/NGenerics">NGenerics</a><br />
Class library providing generic data structures and algorithms not implemented in the standard .NET framework</li>
<li><a href="http://www.codeplex.com/htmlagilitypack">Html Agility Pack</a><br />
Agile HTML parser that builds a read/write DOM and supports plain XPath or XSLT. The parser is very tolerant with &#8220;real world&#8221; malformed HTML. The object model is very similar to System.Xml, but for HTML documents.</li>
</ul>
<p>If you know any other places to find good quality .NET source code then please leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisfulstow.com/reading-other-peoples-net-code/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>.NET Coding Guidelines &#8211; SQL Injection</title>
		<link>http://chrisfulstow.com/coding-guidelines-sql-injection/</link>
		<comments>http://chrisfulstow.com/coding-guidelines-sql-injection/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 00:05:13 +0000</pubDate>
		<dc:creator>Chris Fulstow</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/03/coding-guidelines-sql-injection/</guid>
		<description><![CDATA[In the first of my guidelines for deadbeat developers, I asked why you&#8217;re too lazy to comment your code.  This time, I&#8217;d like to investigate why you build software that&#8217;s catastrophically insecure.
Part 2 &#8211; Protect against SQL injection in .NET
This code will look familiar because it&#8217;s the sort of sloppy mistake you make all <a href="http://chrisfulstow.com/coding-guidelines-sql-injection/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>In the first of my guidelines for deadbeat developers, I asked why you&#8217;re too lazy to <a href="/2007/07/26/coding-guidelines-commenting/">comment your code</a>.  This time, I&#8217;d like to investigate why you build software that&#8217;s catastrophically insecure.</p>
<h2>Part 2 &#8211; Protect against SQL injection in .NET</h2>
<p>This code will look familiar because it&#8217;s the sort of sloppy mistake you make all the time.</p>
<pre><span style="color:blue;">string</span> productId = Request.QueryString[<span style="color:#a31515;">"ProductId"</span>];
<span style="color:blue;">string</span> sql = <span style="color:#a31515;">"delete Products where Id="</span> + productId;
<span style="color:#2b91af;">SqlCommand</span> cmd = <span style="color:blue;">new</span> <span style="color:#2b91af;">SqlCommand</span>(sql);
cmd.ExecuteNonQuery();</pre>
<p>Your feeble imagination doesn&#8217;t stretch far enough to consider what happens when a mischievous user sets productId to, say, &#8220;1 OR 1=1&#8243;.  You merrily build the query, complete with unverified user input, and execute it against the database.</p>
<pre><span style="color:blue;">delete</span> Products <span style="color:blue;">where</span> Id=1 <span style="color:blue;">OR</span> 1=1</pre>
<p>Oh dear, where did all your products go?</p>
<p>A vigilant SQL Server DBA can thwart your stupidity at the database by restricting your access.  By assigning your login to the <a href="http://msdn2.microsoft.com/en-us/library/ms187916.aspx" target="_blank">db_denydatareader</a> and <a href="http://msdn2.microsoft.com/en-us/library/ms188308.aspx" target="_blank">db_denydatawriter</a> roles, you can thankfully be prevented from running any SELECT, DELETE, INSERT or UPDATE queries whatsoever.</p>
<p><img src="http://3poundmass.files.wordpress.com/2007/07/denied.png" alt="SQL Server roles" /></p>
<p>Since you can&#8217;t be trusted, the DBA should give you permissions to execute only the stored-procedures and UDFs you need.  This is the <a href="http://en.wikipedia.org/wiki/Principle_of_least_privilege">principle of least privilege</a>.</p>
<p><img src="http://3poundmass.files.wordpress.com/2007/07/grant-exec1.png" alt="Grant SQL exec permission" /></p>
<p>Parameterised stored-procedures are usually safe from SQL injection because they validate the type and size of the inputs.  These inputs are evaluated as values only, and not executed as part of the SQL statement.  But there is one exception.  When you build SQL dynamically inside the stored-procedure.</p>
<p><span style="color:darkred;">sp_executesql</span> <span style="color:red;">&#8217;select * from Products where Id in &#8216;</span> + @List</p>
<p>This line is from a real stored-procedure I saw last week, @List is a varchar parameter containing something like &#8220;(1,2,3)&#8221;. <span style="color:darkred;"></span>And, of course, the values for @List came from unverified user input.  If you absolutely have to use dynamic SQL then at least clean the inputs and remove or escape anything that could be potentially dangerous.</p>
<p><strong>Read more about SQL injection:</strong></p>
<ul>
<li><a href="http://msdn2.microsoft.com/en-us/library/ms998271.aspx">How To: Protect From SQL Injection in ASP.NET</a></li>
<li><a href="http://msdn2.microsoft.com/en-us/library/ms161953.aspx">SQL Server BOL: SQL Injection</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://chrisfulstow.com/coding-guidelines-sql-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET Coding Guidelines &#8211; Commenting</title>
		<link>http://chrisfulstow.com/coding-guidelines-commenting/</link>
		<comments>http://chrisfulstow.com/coding-guidelines-commenting/#comments</comments>
		<pubDate>Thu, 26 Jul 2007 10:04:48 +0000</pubDate>
		<dc:creator>Chris Fulstow</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/07/26/coding-guidelines-commenting/</guid>
		<description><![CDATA[Let&#8217;s be honest, there&#8217;s only one main purpose to blogging.  To translate concentrated rage into HTML.  To that end, I humbly offer a series of guidelines to you shoddy developers who regularly infect my source tree with your twisted code-wrongs.
Part 1 — Comment your .NET code
You might very well think that. I couldn&#8217;t <a href="http://chrisfulstow.com/coding-guidelines-commenting/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s be honest, there&#8217;s only one main purpose to blogging.  To translate concentrated rage into HTML.  To that end, I humbly offer a series of guidelines to you shoddy developers who regularly infect my source tree with your twisted code-wrongs.</p>
<h2>Part 1 — Comment your .NET code</h2>
<p><q>You might very well think that. I couldn&#8217;t possibly comment.</q><br />
— <a href="http://en.wikipedia.org/wiki/Francis_Urquhart" target="_blank">Francis Urquhart</a></p>
<p>By glancing at your uncommented code I can tell instantly that you&#8217;re either an amateur or, more likely, a lazy and selfish sociopath.  It&#8217;s not like I&#8217;m asking you to write a novel.    Would it really impede your productivity so much that you can&#8217;t find time to furnish your garbled, obfuscated nonsense with some sort of mitigating explanation?    Oh, and when I tell you to start adding comments, I don&#8217;t expect you to start littering code with superfluous crap like:</p>
<pre style="margin:0;">populateControls();       <span style="color:green;">// populate the controls</span></pre>
<pre style="margin:0;"><span style="color:blue;">string</span> name = getName();  <span style="color:green;">// set the name</span></pre>
<p>Comment as you go along, or you&#8217;ll forget.  If you&#8217;re so inclined, use comments to structure your functional design <em>before</em> you write code, this is the <a href="http://www.coderookie.com/2006/tutorial/the-pseudocode-programming-process/">Pseudocode Programming Process</a>.  As a general rule, comment <em>what</em> your code is doing, and <em>why</em> it&#8217;s doing it.  I should already be able to see how your code works, because you&#8217;ve used <em>meaningful</em> and <em>precise</em> names for your classes, functions and variables.</p>
<pre style="margin:0;"><span style="color:green;">// create a SqlConnection object using connectionString</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">SqlConnection</span> cnn = <span style="color:blue;">new</span> <span style="color:#2b91af;">SqlConnection</span>(connectionString);</pre>
<p>I can see you&#8217;re using a SqlConnection because the programming syntax conveniently forces you to include the class type in its variable declaration.  It is also very clear from the code that you&#8217;re passing connectionString as a parameter.  The bigger picture is a mystery.  What is your <em>intent</em>?  Why are you connecting to the database?  What data are you expecting back?  If these things aren&#8217;t clear then explain.</p>
<p>Don&#8217;t comment every single line, instead give a brief summary for each block of related code.  If you&#8217;re working on an API then use a documentation generator like <a href="http://java.sun.com/j2se/javadoc/">Javadoc</a> or <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=E82EA71D-DA89-42EE-A715-696E3A4873B2">SandCastle</a> and format comments accordingly.</p>
<p>Other people will probably have to extend or maintain or your unintelligible mess.  You might think it&#8217;s good for job security if you&#8217;re the only one who can understand your code.   It really isn&#8217;t.</p>
<p><strong>Read more about </strong><strong>commenting </strong><strong>code:</strong></p>
<ul>
<li><a href="http://particletree.com/features/successful-strategies-for-commenting-code/">Successful Strategies for Commenting Code</a></li>
<li><a href="http://www.literateprogramming.com/quotes_sc.html" target="_blank">Literate Programming &#8211; Source Code Comments</a></li>
</ul>
<p><strong> Follow up post:</strong></p>
<ul>
<li><a href="http://3poundmass.wordpress.com/2007/08/22/if-the-code-and-the-comments-disagree-then-both-are-probably-wrong/">If the code and the comments disagree, then both are probably wrong</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://chrisfulstow.com/coding-guidelines-commenting/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
