<?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>// do something here &#187; ASP.NET</title>
	<atom:link href="http://www.dosomethinghere.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dosomethinghere.com</link>
	<description>Turning impossibilities into 1s and 0s professionally since 0&#120;07C1</description>
	<lastBuildDate>Thu, 29 Jul 2010 14:46:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>2010 Central Ohio Day of .NET</title>
		<link>http://www.dosomethinghere.com/2010/06/05/2010-central-ohio-day-of-net/</link>
		<comments>http://www.dosomethinghere.com/2010/06/05/2010-central-ohio-day-of-net/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 23:48:56 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[CONDG]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=535</guid>
		<description><![CDATA[A co-w0rker and I attended the Central Ohio Day of .NET on June 5, 2010. There was quite a bit of good content at the conference, which is a real tribute to the organizers, volunteers, and presenters.
The highlights of my day were sitting in on Matt Casto&#8217;s regular expressions talk, Phil Japikse&#8217;s M-V-VM primer, discussing [...]]]></description>
			<content:encoded><![CDATA[<p>A co-w0rker and I attended the Central Ohio Day of .NET on June 5, 2010. There was quite a bit of good content at the conference, which is a real tribute to the organizers, volunteers, and presenters.</p>
<p>The highlights of my day were sitting in on Matt Casto&#8217;s regular expressions talk, Phil Japikse&#8217;s M-V-VM primer, discussing the etymology of the MongoDB project with Sam Corder (I still say it was named such after the character in Blazing Saddles), Michael Eaton&#8217;s talk on WPF, and Parag Joshi&#8217;s demonstration of XNA/Windows Phone 7 game development.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2010/06/05/2010-central-ohio-day-of-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Control arrays in VB.NET</title>
		<link>http://www.dosomethinghere.com/2009/12/28/control-arrays-in-vb-net/</link>
		<comments>http://www.dosomethinghere.com/2009/12/28/control-arrays-in-vb-net/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 00:57:54 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=443</guid>
		<description><![CDATA[One of the things that I really liked (and used quite a bit) in the VB6 IDE was the ability to use the design surface to create a form with a bunch of controls with the same name as a control array. You would create the controls on the design page, give it the same [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that I really liked (and used quite a bit) in the VB6 IDE was the ability to use the design surface to create a form with a bunch of controls with the same name as a control array. You would create the controls on the design page, give it the same name as another control, and the Index property would automatically be incremented. This would then let me use a loop to manipulate and examine these controls.</p>
<p>This functionality is missing in VB.NET, as I discovered when I tried to do my first .NET Compact Framework application way back when Visual Studio 2003 was shiny and new, and has continued to be missing from the feature set in VS2005 and VS2008.</p>
<p>Microsoft is not much help on this front. Their solution is to create the forms in code, as described in this article:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa289500(VS.71).aspx" target="_blank">Not so helpful link</a></p>
<p>But I like using the design surface to create forms. A co-worker suggested we try to do a test in C# and tamper with the designer.cs file to create an array of controls in there, which worked OK. The big problems there were that the controls showed up on the design surface, but they could not be clicked and modified. Also, when we added a control to the form and saved it, all of the customizations we made to the designer file disappeared. (Oops.)</p>
<p>So instead, what I am now doing is creating my forms in the designer as before, with each control of the set having a different name with a number after it (such as cboName0, cboName1, etc.), referring to the index of the control in the array. At the top of the form&#8217;s class I have the arrays defined:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Dim</span> cboName<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">as</span> ComboBox
<span style="color: #0600FF;">Dim</span> lblNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">as</span> Label</pre></div></div>

<p>Then, in the form load event, I am calling this subroutine:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Sub</span> SetUpControlArrays<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> cb In <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">OfType</span><span style="color: #000000;">&#40;</span>Of ComboBox<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">If</span> cb.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;cboName&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            cboName<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">CInt</span><span style="color: #000000;">&#40;</span>cb.<span style="color: #0000FF;">Name</span>.<span style="color: #0600FF;">Replace</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;cboName&quot;</span>, <span style="color: #808080;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> cb
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #FF8000;">Next</span>
&nbsp;
    <span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> lbl In <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">OfType</span><span style="color: #000000;">&#40;</span>Of Label<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">If</span> lbl.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;lblNumber&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            lblNumber<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">CInt</span><span style="color: #000000;">&#40;</span>lbl.<span style="color: #0000FF;">Name</span>.<span style="color: #0600FF;">Replace</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;lblNumber&quot;</span>, <span style="color: #808080;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> lbl
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #FF8000;">Next</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></div></div>

<p>Now I have the ability to address the controls in the same way that I used to do in VB6. The fact that I lived with this missing feature for about 6 years and just now figuring out a decent way around the problem pretty much guarantees that VS2010 will put the control arrays back in.</p>
<p><strong>EDIT:</strong> At the request of a Strong Bad fan who shall remain nameless, I changed up the code above to be a bit more friendly. The previous code only extracted the rightmost 1 character from the name of the control on the design surface, which would not work if you had a control name such as cboName10.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/12/28/control-arrays-in-vb-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Friends don&#8217;t let friends reinvent System.Security.Cryptography</title>
		<link>http://www.dosomethinghere.com/2009/07/19/friends-dont-let-friends-reinvent-system-security-cryptography/</link>
		<comments>http://www.dosomethinghere.com/2009/07/19/friends-dont-let-friends-reinvent-system-security-cryptography/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 14:23:07 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Inspirational code]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=189</guid>
		<description><![CDATA[A fellow coworker is upgrading one of our long time customer&#8217;s ASP.NET web site that was originally created in 2003, and all is going swimmingly. Alas, this project could not go gently into that good night.
He makes the web page and code changes, modifies the database, pushes all the changes up to the web site, and [...]]]></description>
			<content:encoded><![CDATA[<p>A fellow coworker is upgrading one of our long time customer&#8217;s ASP.NET web site that was originally created in 2003, and all is going swimmingly. Alas, this project could not go gently into that good night.</p>
<p>He makes the web page and code changes, modifies the database, pushes all the changes up to the web site, and the site is working well. Customers are placing orders on the web site, order e-mails are being sent to the site owners with encrypted credit card information, and all are happy.</p>
<p>But there is always a fly in the ointment. All of a sudden, an order is placed on the web site, but when the site owner tries to run a decrypt on the credit card information in the e-mail, the decryption routine is reporting a failure. So naturally, we assume that we broke the code somehow, so we started to dive into the project to see what we did to destabilize it.</p>
<p>He asked for my opinions on this problem, so I came over and we started to go through the VB.NET Framework v2.0 project. While investigating the area of the code containing the exact message that the customer was getting, my blood pressure started to go up right away as we started to see code that looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">If</span> intNumberLength <span style="color: #008000;">=</span> <span style="color: #FF0000;">16</span> <span style="color: #FF8000;">Then</span>
    <span style="color: #008080; font-style: italic;">'go through each of the 16 numbers and</span>
    <span style="color: #008080; font-style: italic;">'add the code for them into the return string</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">5</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">6</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">6</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">7</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">8</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">9</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">9</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">10</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">11</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">11</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">12</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">12</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">13</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">13</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">14</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">14</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">15</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">15</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">16</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
&nbsp;
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char1<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char2<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char3<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char4<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char5<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char6<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">6</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char7<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">6</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char8<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char9<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">9</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char10<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">9</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char11<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">11</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char12<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">11</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">12</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char13<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">12</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">13</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char14<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">13</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">14</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char15<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">14</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">15</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char16<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">15</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">'strReturnValue = strCharCodes.ToString</span>
<span style="color: #FF8000;">ElseIf</span> intNumberLength <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span> <span style="color: #FF8000;">Then</span>
    <span style="color: #008080; font-style: italic;">' you get the idea</span></pre></div></div>

<p>And this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'first char</span>
<span style="color: #0600FF;">Select</span> <span style="color: #0600FF;">Case</span> <span style="color: #0600FF;">Left</span><span style="color: #000000;">&#40;</span>strEncodeCard, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>    <span style="color: #008080; font-style: italic;">' these character constants were originally all different</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;0&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>    <span style="color: #008080; font-style: italic;">' I have masked them out for this blog posting</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;1&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;2&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;3&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;4&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;5&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;6&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;7&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;8&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;9&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF8000;">Else</span>
        blnSuccess <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Select</span></pre></div></div>

<p>(The above code was repeated 32 times, once for each digit of a potential 16 digit credit card number, and there were two sets of these that were switched if the digit position was odd or even. There was definitely some thought put into this. I&#8217;m not saying it was good thought, just thought. Perhaps they were paid by the lines of code written?)</p>
<p>OK, I have done things like this from time to time, usually not to this extent, but the original designers and coders of this project at least had the good sense to encrypt the credit card information that was being e-mailed, so maybe it will get better.</p>
<p>Yeah, I was wrong about that, I should remember a tenet of code maintenance that I learned a long time ago: TWGW. (This stands for Things Will Get Worse.) As we stepped through the order that was confusing the system, we came upon this nugget.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'second, select the expiration year code</span>
<span style="color: #0600FF;">Select</span> <span style="color: #0600FF;">Case</span> intExpYear
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2003</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>    <span style="color: #008080; font-style: italic;">' these character constants were originally all different</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2004</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>    <span style="color: #008080; font-style: italic;">' I have masked them out for this blog posting</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2005</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2006</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2007</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2008</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2009</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2010</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2011</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2012</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Select</span></pre></div></div>

<p>Of course, the customer had a credit card that expired in 2013, and as such, no character was begin inserted into the encrypted string for the expiration year, and that was causing the problem.</p>
<p>I don&#8217;t even know where to begin, except to say that eventually this code was going to break, and that was the day. (System.Security.Cryptography was in .NET Framework v1.1, so they can&#8217;t use that as an excuse.) So the moral of the story is, if you are going to reinvent a Microsoft namespace, at least make it work more than six years.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/07/19/friends-dont-let-friends-reinvent-system-security-cryptography/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>If at first you don&#8217;t succeed, try try (catch catch) again</title>
		<link>http://www.dosomethinghere.com/2009/05/13/if-at-first-you-dont-succeed-try-try-catch-catch-again/</link>
		<comments>http://www.dosomethinghere.com/2009/05/13/if-at-first-you-dont-succeed-try-try-catch-catch-again/#comments</comments>
		<pubDate>Thu, 14 May 2009 02:18:17 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Inspirational code]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=66</guid>
		<description><![CDATA[So I am cruising through the ASP.NET C# MVP web project we are working on, and happened upon this method (again, the names were changed to protect the not so innocent):

private void mView_LoadObjects&#40;object sender, EventArgs e&#41;
&#123;
    try
    &#123;
        try
    [...]]]></description>
			<content:encoded><![CDATA[<p>So I am cruising through the ASP.NET C# MVP web project we are working on, and happened upon this method (again, the names were changed to protect the not so innocent):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> mView_LoadObjects<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">try</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">try</span>
        <span style="color: #000000;">&#123;</span>
            BusinessLayer.<span style="color: #0000FF;">Class1</span> bizClass <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BusinessLayer.<span style="color: #0000FF;">Class1</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            mView.<span style="color: #0000FF;">objects</span> <span style="color: #008000;">=</span> bizClass.<span style="color: #0000FF;">GetObjects</span><span style="color: #000000;">&#40;</span>mView.<span style="color: #0000FF;">ID1</span>, mView.<span style="color: #0000FF;">ID2</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            throw<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        throw<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>However, the fun didn&#8217;t stop there.  A little further down the class, I found this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> mView_LoadOtherObjects<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">try</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        throw<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I am thinking that the catch block on this second example was not hit very often.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/05/13/if-at-first-you-dont-succeed-try-try-catch-catch-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ELMAH for ASP.NET</title>
		<link>http://www.dosomethinghere.com/2009/05/06/elmah-for-aspnet/</link>
		<comments>http://www.dosomethinghere.com/2009/05/06/elmah-for-aspnet/#comments</comments>
		<pubDate>Thu, 07 May 2009 01:24:43 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=59</guid>
		<description><![CDATA[My company has been doing ASP.NET development for a few years now, and we have had varying success in dealing with exceptions. In a Scott Hanselman blog post, I found out about ELMAH (Error Logging Modules and Handlers), which can assist development of ASP.NET web sites.
After some configuration issues in the Web.config file, we were [...]]]></description>
			<content:encoded><![CDATA[<p>My company has been doing ASP.NET development for a few years now, and we have had varying success in dealing with exceptions. In a <a href="http://www.hanselman.com/blog/ELMAHAndExceptionDrivenDevelopmentFTW.aspx" target="_blank">Scott Hanselman blog post</a>, I found out about ELMAH (Error Logging Modules and Handlers), which can assist development of ASP.NET web sites.</p>
<p>After some configuration issues in the Web.config file, we were able to get it working fine on my local machine. We have not tried using it in a production environment, but I would guess that it should work fine as long as we create the appropriate folder on the web server to save the XML files.</p>
<p>I suspect that we have only begun to scratch the surface of what is possible with ELMAH, but I would reiterate what many others have said. Anyone doing ASP.NET web development should be using ELMAH.</p>
<p>Here are a couple of links:</p>
<p><a href="http://code.google.com/p/elmah/" target="_blank">ELMAH project home</a></p>
<p><a href="http://code.google.com/p/elmah/wiki/DotNetSlackersArticle" target="_blank">DotNetSlackersArticle introductory article by Simone Busoli</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/05/06/elmah-for-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
