<?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>XYZPDQ</title>
	<atom:link href="http://xyzpdq.org/feed/?containerid=11" rel="self" type="application/rss+xml" />
	<link>http://xyzpdq.org</link>
	<description>Ramblings of a coder</description>
	<lastBuildDate>Sun, 19 May 2013 09:33:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Monitor Windows EC2 Instance Free Drivespace via Cloudwatch</title>
		<link>http://xyzpdq.org/2013/04/monitor-windows-ec2-instance-free-drivespace-via-cloudwatch/</link>
		<comments>http://xyzpdq.org/2013/04/monitor-windows-ec2-instance-free-drivespace-via-cloudwatch/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 11:09:10 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/?p=155</guid>
		<description><![CDATA[<p>Amazon offers a lot of great CloudWatch metrics out of the box for EC2 instances, but there is a key metric that is missing.&#160; Remaining available drive space. Luckily, there is a relatively easy way to resolve this.&#160; AWS offers &#8230; <a href="http://xyzpdq.org/2013/04/monitor-windows-ec2-instance-free-drivespace-via-cloudwatch/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2013/04/monitor-windows-ec2-instance-free-drivespace-via-cloudwatch/">Monitor Windows EC2 Instance Free Drivespace via Cloudwatch</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Amazon offers a lot of great <a href="http://aws.amazon.com/cloudwatch/" target="_blank">CloudWatch</a> metrics out of the box for EC2 instances, but there is a key metric that is missing.&nbsp; Remaining available drive space.</p>
<p>Luckily, there is a relatively easy way to resolve this.&nbsp; AWS offers us the ability to add in our own metrics that allow us to monitor pretty much anything we want.&nbsp; In this case, we are going to create something to report back to CloudWatch about the free drivespace on our EC2 instance.</p>
<p>In preparation for this exercise, we are going to do a little prep work.</p>
<p>To start, ensure that the <a href="http://aws.amazon.com/sdkfornet/" target="_blank">AWS SDK for .Net</a> is available on your EC2 instance.&nbsp; It should exist in &#8220;<strong>C:\Program Files (x86)\AWS SDK for .NET\</strong>&#8221; by default.&nbsp; If it doesn’t for whatever reason, download and install it.</p>
<p>Next, collect your Access Key and the Access Key Secret and put them to the side.&nbsp; They’ll be used shortly.</p>
<p>The last thing you will need to gather is the instance ID for the EC2 instance that we’re going to collect metrics for.&nbsp; If you are uncertain what this is, there are a few different ways to find it.&nbsp; If you are running a more recent image, it is in the top right corner on the background image.&nbsp; The best way to get the instance ID however is to log in to the AWS Management Console, go to the EC2 section and the instance ID will be shown in the grid.&nbsp; It should start with a lowercase “i&#8221; followed by a dash and a hex string. e.g. i-a1b2c3d4</p>
<p>The next step is putting together a PowerShell script that will utilize all of the things that we have collected to this point to gather and report on the metrics that we’re after.</p>
<p>So, let’s get started.</p>
<p>Open your preferred PowerShell script editor and create a new ps1 file.&nbsp; It doesn’t matter what it is called. I named mine <strong>updatedrivespacemetrics.ps1 </strong>for clarity.</p>
<p>At the top of the script, we are going to import the AWS assembly and set the access key values.</p>
<pre class="prettyprint">#Import the AWS SDK assembly<br />Add-Type -Path "C:\Program Files (x86)\AWS SDK for .NET\bin\AWSSDK.dll"
#Credentials
$secretAccessKeyID="1234567890ABCDEF1234567890ABCDEF12345678"
$secretKeyID="ABCDEF1234567890ABCD"
#Get Instance ID
$instanceId="i-a1b2c3d4"</pre>
<p>Next, create a request object to store the new Metrics and give it a name that you will be able to easily recognize later on.</p>
<pre class="prettyprint">#Create request<br />$request = New-Object -TypeName Amazon.CloudWatch.Model.PutMetricDataRequest
$request.NameSpace = "CUSTOM-Freespace"</pre>
<p>Time to collect the values.&nbsp; We are going to use WMI to get the freespace from the drives on our instance.</p>
<pre class="prettyprint">#Get Free Space
$freeSpace=Get-WmiObject -Class Win32_LogicalDisk | Select-Object -Property DeviceID, @{Name='FreeSpaceGB';Expression={$_.FreeSpace/1GB}} | Where-Object {$_.DeviceID -eq "C:" -or $_.DeviceID -eq "D:" }</pre>
<p>Let’s look at what this statement is doing.</p>
<pre class="prettyprint">Get-WmiObject -Class Win32_LogicalDisk</pre>
<p>This will return an array of all of the drives on the machine with their <em>DeviceID, DriveType, Freespace, Size</em> and <em>VolumeName</em>.&nbsp; </p>
<p>From this array, we are going to select the <em>DeviceID </em>and the <em>FreeSpace</em>.&nbsp; However, <em>FreeSpace </em>is returning bytes and we need something that is a little easier to parse, so we are going to turn it into gigabytes.&nbsp; To do this we are going to use an expression to modify the property value before we pull it back.</p>
<pre class="prettyprint">@{Name='FreeSpaceGB';Expression={$_.FreeSpace/1GB}}</pre>
<p>Last, we are going to limit the drives that we pull back.&nbsp; This part is optional, but can be useful if there are only specific drives that you are interested in.&nbsp; In this case, I have narrowed it down to the C and D drives.</p>
<pre class="prettyprint">Where-Object {$_.DeviceID -eq "C:" -or $_.DeviceID -eq "D:" }</pre>
<p>Time to start collecting this information into a way that AWS can parse it.&nbsp; The first step to do this is creating some basic dimensions that will differentiate our custom metric.&nbsp; To keep things simple we are going to create two dimensions, <em>Role</em> and <em>InstanceID</em>.&nbsp; </p>
<pre class="prettyprint">#Create dimensions
$dimensions = New-Object System.Collections.ArrayList
$dimension1 = New-Object -TypeName Amazon.CloudWatch.Model.Dimension
$dimension2 = New-Object -TypeName Amazon.CloudWatch.Model.Dimension

$dimension1.Name = "Role"
$dimension1.Value = "Test Server"
$dimension2.Name = "InstanceID"
$dimension2.Value = $instanceId

$dimensions.Add($dimension1)
$dimensions.Add($dimension2)</pre>
<p>With the dimensions in hand we are going to put everything together into a metric.&nbsp; For each drive that we collected information on earlier, we are going to create a <em>MetricDatum </em>and populate it with the appropriate values.&nbsp; </p>
<pre class="prettyprint">#Create metrics
$metrics = New-Object System.Collections.ArrayList

Foreach ($item in $freeSpace) 
{
	$metric = New-Object -TypeName Amazon.CloudWatch.Model.MetricDatum
	$metric.MetricName = $item.DeviceID + "free space"
	$metric.Value = $item.FreeSpaceGB
	$metric.Unit = "Gigabytes"
	$metric=$metric.WithDimensions($dimensions)
	$metrics.Add($metric)
}</pre>
<p>After the metrics are created, we need to update the request object that we created earlier with the metrics data</p>
<pre class="prettyprint">$request = $request.WithMetricData($metrics)</pre>
<p>Finally, we are going to submit all of this information back to AWS.</p>
<pre class="prettyprint">#Perform the request
$client=[Amazon.AWSClientFactory]::CreateAmazonCloudWatchClient($secretKeyID,$secretAccessKeyID)
$response=$client.PutMetricData($request)</pre>
<p>That’s it!&nbsp; Now we have a script that will push information on available drivespace up to CloudWatch.&nbsp; The first time it is run it will create the metric if it doesn’t exist.&nbsp; Each subsequent time, it will just add a new data point to the existing metric.</p>
<p>The final step is scheduling this so that it runs consistently.&nbsp; The easiest way to accomplish this is the built in Windows Task Scheduler.&nbsp; I won’t go through the steps for that here, but I would suggest setting it up to run every 5 minutes.&nbsp; If you are uncertain how to call your script, <strong>“powershell c:\jobs\updatedrivespacemetrics.ps1”</strong> will get the job done (replace c:\jobs\ with the location of your script).</p>
<p><a href="http://xyzpdq.org/wp-content/uploads/2013/04/cloudwatch.gif"><img title="cloudwatch" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 10px 0px 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="cloudwatch" align="left" src="http://xyzpdq.org/wp-content/uploads/2013/04/cloudwatch_thumb.gif" width="244" height="169"></a>Now that you have everything set up, you can go into the AWS management console, go to the CloudWatch page and you should see your new metric.&nbsp; </p>
<p>Note:&nbsp; You will need to set this up for each instance that you want to gather drivespace on.&nbsp; Each instance will need its own copy of the script and have the task scheduler set up appropriately.&nbsp; As you copy the script from instance to instance, you will need to change the InstanceID in the script to reflect the appropriate instance.</p>
<p>The post <a href="http://xyzpdq.org/2013/04/monitor-windows-ec2-instance-free-drivespace-via-cloudwatch/">Monitor Windows EC2 Instance Free Drivespace via Cloudwatch</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2013/04/monitor-windows-ec2-instance-free-drivespace-via-cloudwatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Small Design decisions with a large impact</title>
		<link>http://xyzpdq.org/2013/03/small-design-decisions-with-a-large-impact/</link>
		<comments>http://xyzpdq.org/2013/03/small-design-decisions-with-a-large-impact/#comments</comments>
		<pubDate>Sun, 03 Mar 2013 11:54:45 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/?p=93</guid>
		<description><![CDATA[<p>I checked into a nice hotel yesterday. I was very impressed with the room and promptly set about unpacking my things. Because I had been traveling for nearly 20 hours straight, my devices were desperately in need of power. The &#8230; <a href="http://xyzpdq.org/2013/03/small-design-decisions-with-a-large-impact/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2013/03/small-design-decisions-with-a-large-impact/">Small Design decisions with a large impact</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I checked into a nice hotel yesterday.  I was very impressed with the room and promptly set about unpacking my things.  Because I had been traveling for nearly 20 hours straight, my devices were desperately in need of power.  </p>
<p>The lamp next to the bed conveniently had an outlet in the base of the lamp.</p>
<p><a href="http://xyzpdq.org/wp-content/uploads/2013/03/20130303-065721.jpg"><img src="http://xyzpdq.org/wp-content/uploads/2013/03/20130303-065721.jpg" alt="20130303-065721.jpg" class="alignnone size-full" /></a></p>
<p>I do not have a US spec power supply for my laptop, so I am forged to use an adaptor.  Now, granted, the adaptor that I have is rather comically large, (my primary one broke and I was forced to find this rather inadequate replacement) but it does serve to illustrate a point.<br />
<br /><a href="http://xyzpdq.org/wp-content/uploads/2013/03/20130303-070014.jpg"><img src="http://xyzpdq.org/wp-content/uploads/2013/03/20130303-070014.jpg" alt="20130303-070014.jpg" class="alignnone size-full" /></a></p>
<p>By simply rotating the outlet 90 degrees, this problem would not exist.  Again, I realize this is a somewhat extreme use case, but in the instance where the plug was directly on the power brick, as is the case with many devices, this would still be an issue.</p>
<p>The post <a href="http://xyzpdq.org/2013/03/small-design-decisions-with-a-large-impact/">Small Design decisions with a large impact</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2013/03/small-design-decisions-with-a-large-impact/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>S3 directory browsing from a custom subdomain</title>
		<link>http://xyzpdq.org/2013/02/s3-directory-browsing-from-a-custom-subdomain/</link>
		<comments>http://xyzpdq.org/2013/02/s3-directory-browsing-from-a-custom-subdomain/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 20:30:21 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/?p=88</guid>
		<description><![CDATA[<p>This week I was asked to set up a site on our server with directory browsing enabled.  They also wanted to be able to upload files to said site.  Since we are already hosting our servers on AWS, I suggested &#8230; <a href="http://xyzpdq.org/2013/02/s3-directory-browsing-from-a-custom-subdomain/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2013/02/s3-directory-browsing-from-a-custom-subdomain/">S3 directory browsing from a custom subdomain</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>This week I was asked to set up a site on our server with directory browsing enabled.  They also wanted to be able to upload files to said site.  Since we are already hosting our servers on AWS, I suggested to them that rather than expending the effort to write code to allow them to manage everything via the web, we set up an S3 bucket and allow them to manage the files directly from their desktop.</p>
<p>Somehow I had gotten to this point in time without working with S3.  I am aware of the principle behind it however and I knew it was capable of doing what I had proposed.</p>
<p>Creating a new bucket was easy. Configuring the permissions on the bucket to allow anonymous users was also easy.  Mapping the bucket to a sub-domain and enabling file browsing is where everything started to fall apart on me.</p>
<p>I logged on to AWS and created the bucket.  For the sake of example, let&#8217;s say it was called <strong>assets.mysite.com</strong>.  Something important to note here.  If you are planning on mapping the bucket to a sub-domain like I am in this example, it is typically best practice to make the name of the bucket the same as the sub-domain.</p>
<p>From there I set the permissions to enable everyone to be able to list the contents of the bucket.</p>
<p>Since I knew that my ultimate goal was to map this bucket to a sub-domain on the site, I immediately clicked down to the next tab &#8220;Static Website Hosting&#8221;, checked &#8220;Enable website hosting&#8221;, added an index document and clicked &#8220;Save&#8221;.  I copied the Endpoint that was provided on that tab <strong>assets.mysite.com.s3-website-us-east-1.amazonaws.com</strong>, jumped over to Route53 and added a CNAME for <strong>assets.mysite.com </strong>and dropped in the provided Endpoint.</p>
<p>Because I do my research, I knew that to get a list of files to show up, I would need to drop in some javascript to parse the XML content.  I grabbed some <a title="Amazon S3 bucket listing" href="http://aws.amazon.com/code/JavaScript/1713" target="_blank">bucket listing code from the AWS community</a> and uploaded it to the bucket.</p>
<p>Simple. Right?</p>
<p>Wrong.</p>
<p>The listing page loaded, but it didn&#8217;t show any of the content that I knew had been uploaded to the bucket.  I start going back through everything I had done, checking for the mistake.  I couldn&#8217;t find anything wrong.  I dug through the permissions thinking that perhaps something was off there.  Nothing.  So, I started going through the script and decomposing it to see if perhaps something was not working correctly with the script.  I found the following line where it pulls the list of available content:</p>
<pre class="prettyprint">http.open('get', location.protocol+'//'+location.hostname);</pre>
<p>Aha!  So, I tried browsing to <strong>assets.mysite.com</strong> and all I got was a 404 error.  Thinking at this point that perhaps configuring things as a website is what caused the problem, I went back in and disabled the website hosting feature.  I tried again and got a 404 error again.  That was obviously not the issue.</p>
<p>Eventually, after poking around for a while, I stumbled across a different endpoint <strong>assets.mysite.com.s3.amazonaws.com</strong>.  This returned the XML that I was expecting!  Armed with this new information, I went back and modified the line from the script that was reaching out for the XML to:</p>
<pre class="prettyprint">http.open('get', 'http://assets.mysite.com.s3.amazonaws.com');</pre>
<p>Surely this was going to solve my problem &#8230; or not.</p>
<p>This time I am getting a 405 error.  I immediately start googling and digging through the documentation and discover that the issue I am running into is because I am trying to do cross site scripting.  <strong>assets.mysite.com</strong> needs permission to talk to <strong>assets.mysite.com.s3.amazonaws.com</strong>. Armed with a little more information now, I run back into the S3 management console and start looking at the options available to me in the permissions tab.  I click on the &#8220;Edit CORS Configuration&#8221; button and edited the rules to include:</p>
<pre class="prettyprint">&lt;CORSRule&gt;
&lt;AllowedOrigin&gt;*&lt;/AllowedOrigin&gt;
&lt;AllowedMethod&gt;GET&lt;/AllowedMethod&gt;
&lt;/CORSRule&gt;</pre>
<p>Now when I go to the listing page, I see all of my files!  Mission successful.</p>
<p>Hopefully this can help some of you out.  Myself and a coworker tore (what&#8217;s left of) our hair out for a while going through all of the motions on this.</p>
<p>The post <a href="http://xyzpdq.org/2013/02/s3-directory-browsing-from-a-custom-subdomain/">S3 directory browsing from a custom subdomain</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2013/02/s3-directory-browsing-from-a-custom-subdomain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Email Templates and MailTo Syntax</title>
		<link>http://xyzpdq.org/2013/01/email-templates-and-mailto-syntax/</link>
		<comments>http://xyzpdq.org/2013/01/email-templates-and-mailto-syntax/#comments</comments>
		<pubDate>Sun, 20 Jan 2013 09:34:07 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/?p=74</guid>
		<description><![CDATA[<p>The mailto prefix in hyperlinks.&#160; Everyone knows about it, everyone uses it.&#160; Not very many people are aware however that it can do more than just pass an email address to your user’s favorite email program.&#160; I was in a &#8230; <a href="http://xyzpdq.org/2013/01/email-templates-and-mailto-syntax/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2013/01/email-templates-and-mailto-syntax/">Email Templates and MailTo Syntax</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>The <strong>mailto</strong> prefix in hyperlinks.&nbsp; Everyone knows about it, everyone uses it.&nbsp; Not very many people are aware however that it can do more than just pass an email address to your user’s favorite email program.&nbsp; </p>
<p>I was in a situation the other day where I needed to prompt a user for specific information, but I did not want / need to go to the effort of writing a contact form.&nbsp; Yes, I realize writing a contact form would have only taken a few minutes, but sometimes being a little bit lazy can work out well.&nbsp; </p>
<p>So, just to remind everybody and give us a starting place, let’s create a basic mailto link</p>
<pre class="prettyprint">&lt;a href=”mailto:youremail@domain.com”&gt;Contact Us&lt;/a&gt;</pre>
<p>First, let’s look at adding in more than just s single address.&nbsp; There are two options here.&nbsp; We can simply add multiple addresses divided by commas, or we can specify CC and BCC.</p>
<pre class="prettyprint">&lt;a href=”mailto:youremail@domain.com, <a href="mailto:youremail2@domain.com&rdquo;&gt;Contact">youremail2@domain.com”&gt;Contact</a> Us&lt;/a&gt;</pre>
<pre class="prettyprint">&lt;a href=”mailto:youremail@domain.com?cc=yourccemail@domain.com”&gt;Contact Us&lt;/a&gt;</pre>
<pre class="prettyprint">&lt;a href=”mailto:youremail@domain.com?bcc=yourbccemail@domain.com”&gt;Contact Us&lt;/a&gt;</pre>
<p>Now, let’s take a look at passing through a subject.&nbsp; It is essentially the same principle as the CC and BCC options.</p>
<pre class="prettyprint">&lt;a href=”mailto:youremail@domain.com?subject=Please write me back”&gt;Contact Us&lt;/a&gt;</pre>
<p>Finally, the body of the email.&nbsp; This is where my unwillingness to write a contact form comes into play.</p>
<pre class="prettyprint">&lt;a href=”mailto:youremail@domain.com?body=Sample Body Content”&gt;Contact Us&lt;/a&gt;</pre>
<p>I can hear you now, that’s great, but what if I want more complicated substance to my email body?&nbsp; What if I need multiple paragraphs.&nbsp; Well, you can do that, but it is <em>not completely supported </em>in every email client yet.&nbsp; All of the more recent iterations of the email clients should have no issues however.&nbsp; The trick to passing paragraph information is obviously URL encoding a line break.&nbsp; You can accomplish this by placing %0A where you would like a line break.&nbsp; Extrapolating that, %0A%0A would give us a paragraph break.&nbsp; Let’s look at an example.</p>
<pre class="prettyprint">&lt;a href=”mailto:youremail@domain.com?body=Sample Paragraph One%0A%0ASample Paragraph Two”&gt;Contact Us&lt;/a&gt;</pre>
<p>Ok.&nbsp; We’ve looked at all the options, so, now we can chain all of these together into our Contact Form link.&nbsp; To chain multiple items together, utilize the &amp; character just like you would in a URL.</p>
<pre class="prettyprint">&lt;a href=”mailto:youremail@domain.com?cc=yourccemail@domain.com&amp;subject=Please write me back&amp;body==Sample Paragraph One%0A%0ASample Paragraph Two”&gt;Contact Us&lt;/a&gt;</pre>
<p>There you have it.</p>
<p>The post <a href="http://xyzpdq.org/2013/01/email-templates-and-mailto-syntax/">Email Templates and MailTo Syntax</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2013/01/email-templates-and-mailto-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote Reboot of Windows 7</title>
		<link>http://xyzpdq.org/2010/11/remote-reboot-of-windows-7/</link>
		<comments>http://xyzpdq.org/2010/11/remote-reboot-of-windows-7/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 22:45:00 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/blog/?p=63</guid>
		<description><![CDATA[<p>I ran into an interesting problem recently where I was (admittedly) too lazy to walk upstairs and reboot my desktop that I use as a home server. I connected via remote desktop only to discover that I was not able &#8230; <a href="http://xyzpdq.org/2010/11/remote-reboot-of-windows-7/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2010/11/remote-reboot-of-windows-7/">Remote Reboot of Windows 7</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I ran into an interesting problem recently where I was (admittedly) too lazy to walk upstairs and reboot my desktop that I use as a home server.
<p>I connected via remote desktop only to discover that I was not able to reboot the machine from the start menu via a RDC.&nbsp;
<p>Curiosity, persistence (and laziness) prevailed and I spent some time researching to figure out how to get around this pesky issue.
<p>Being a lover of most things related to the command prompt, I fired one up in admin mode (since like a good user, my account is not an administrator by default) and tried to reboot using
<p><code>shutdown /r /t 0</code> only to be thwarted with a<code>Access is Denied(5).</code> message.&nbsp;
<p>Researching this told me what was already plainly obvious, it was a permissions issue and I did not have permissions to do what I wanted.
<p>Digging a little further, I came across the solution.
<ol>
<li>Open the policy editor (secpol.msc)
<li>Expand Local Policies
<li>Select User Rights Assignment
<li>Find the Force shutdown from a remote system policy and add your account.
<li>Once this is done, go to a command prompt and run gpupdate</li>
</ol>
<p>Now, when you run shutdown /r /t 0, your remote computer will promptly heed your wishes and restart.</p>
<p>The post <a href="http://xyzpdq.org/2010/11/remote-reboot-of-windows-7/">Remote Reboot of Windows 7</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2010/11/remote-reboot-of-windows-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting a .Net list with lambdas</title>
		<link>http://xyzpdq.org/2010/04/sorting-a-net-list-with-lambdas/</link>
		<comments>http://xyzpdq.org/2010/04/sorting-a-net-list-with-lambdas/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 22:46:00 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/blog/?p=64</guid>
		<description><![CDATA[<p>I love linq.&#160; I would wager that most developers who have done much with it share a similar love. It makes our lives easier.&#160; It eliminates writing copies amounts of loops, parsing xml, interacting with databases, you name it.&#160; It’s &#8230; <a href="http://xyzpdq.org/2010/04/sorting-a-net-list-with-lambdas/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2010/04/sorting-a-net-list-with-lambdas/">Sorting a .Net list with lambdas</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I love linq.&nbsp; I would wager that most developers who have done much with it share a similar love.
<p>It makes our lives easier.&nbsp; It eliminates writing copies amounts of loops, parsing xml, interacting with databases, you name it.&nbsp; It’s great.
<p>When I run into a situation where linq does not have an obvious tie in, I start to get a little anxious,&nbsp; (pathetic I realize).
<p>Today I was faced with a situation where I had a list of custom classes that I needed to sort.&nbsp;
<p>This being a list, OrderBy was nowhere to be found.
<p>So, I returned to my roots and started writing a compare for my class so that I could use the Sort command that <em>is </em>part of the List generic type.&nbsp; That is when it struck me that I could probably accomplish this using a lambda.&nbsp; It turns out that I was correct.&nbsp; Lambda’s were a perfect fit for this scenario.&nbsp; The code remained clean and concise and I was saved having to write additional methods just to accomplish a one-off scenario on what was a otherwise complete project.
<p>Lamdas are a progression in C# past anonymous methods.&nbsp; In the code below, I show how the code would be implemented with separate function, an anonymous method and finally, with a Lambda expression.
<p>First, the test class that we’ll be working with:</p>
<pre>public class MyClass
{
    public int propA { get; set; }
    public int propB { get; set; }
    public int propC { get; set; }
}</pre>
<p>Our test class:</p>
<pre>public class Tester
{
    public void Main()
    {
        List list = new List();
        list.Add(new MyClass() { propA = 1, propB = 2, propC = 3 });
        list.Add(new MyClass() { propA = 2, propB = 3, propC = 4 });
        list.Add(new MyClass() { propA = 3, propB = 4, propC = 5 });
        list.Add(new MyClass() { propA = 4, propB = 5, propC = 6 });        
    }
}</pre>
<p>Now then, we write a custom comparer.&nbsp; Not a <em>lot</em>of code, but you can imagine how this extrapolates over various properties for large classes.</p>
<pre>public class Tester
{
    private static int CompareByPropA(MyClass a, MyClass b)
    {
        return a.propA.CompareTo(b.propA);
    }
    public void Main()
    {
        List list = new List();
        list.Add(new MyClass() { propA = 1, propB = 2, propC = 3 });
        list.Add(new MyClass() { propA = 2, propB = 3, propC = 4 });
        list.Add(new MyClass() { propA = 3, propB = 4, propC = 5 });
        list.Add(new MyClass() { propA = 4, propB = 5, propC = 6 });

        //Using the comparer built into the MyClass method
        list.Sort(CompareByPropA);        
    }
}</pre>
<p>This time, we drop the custom comparer and implement the sort using an anonymous method.</p>
<pre>public class Tester
{
    public void Main()
    {
        List list = new List();
        list.Add(new MyClass() { propA = 1, propB = 2, propC = 3 });
        list.Add(new MyClass() { propA = 2, propB = 3, propC = 4 });
        list.Add(new MyClass() { propA = 3, propB = 4, propC = 5 });
        list.Add(new MyClass() { propA = 4, propB = 5, propC = 6 });

        //Using an anonymous method
        list.Sort(delegate(MyClass a, MyClass b) { return a.propA.CompareTo(b.propA); });
    }
}</pre>
<p>Finally, we rewrite the anonymous method into a Lambda.&nbsp; It is still easy to read and much more concise.</p>
<pre>public class Tester
{
    public void Main()
    {
        List list = new List();
        list.Add(new MyClass() { propA = 1, propB = 2, propC = 3 });
        list.Add(new MyClass() { propA = 2, propB = 3, propC = 4 });
        list.Add(new MyClass() { propA = 3, propB = 4, propC = 5 });
        list.Add(new MyClass() { propA = 4, propB = 5, propC = 6 });

        //Using a Lambda
        list.Sort((a, b) =&gt; a.propA.CompareTo(b.propA));
    }
}</pre>
<p>So, next time you go to write custom compare code, step back and see if you can do it a little more simply.&nbsp; If you are going to be using your comparison code in more than one place, then perhaps it is still a better idea to implement it using that route vs the lambda.&nbsp; If it is a one-off thing, then a lambda and some linq can be a beautiful thing!</p>
<p>The post <a href="http://xyzpdq.org/2010/04/sorting-a-net-list-with-lambdas/">Sorting a .Net list with lambdas</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2010/04/sorting-a-net-list-with-lambdas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review of Flex 4 in Action</title>
		<link>http://xyzpdq.org/2010/03/review-of-flex-4-in-action/</link>
		<comments>http://xyzpdq.org/2010/03/review-of-flex-4-in-action/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 22:47:00 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/blog/?p=65</guid>
		<description><![CDATA[<p>As someone who has relatively little experience with Flex, I found this book to be a great asset in furthering my understanding of how and why things work the way they do not only in MXML, but also on the &#8230; <a href="http://xyzpdq.org/2010/03/review-of-flex-4-in-action/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2010/03/review-of-flex-4-in-action/">Review of Flex 4 in Action</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>As someone who has relatively little experience with Flex, I found this book to be a great asset in furthering my understanding of how and why things work the way they do not only in MXML, but also on the ActionScript side.
<p>The tone of the book is very friendly.&nbsp; As a general rule, I did not find myself bogged down in technical terminology.&nbsp; A good balance was struck between keeping things simple for the average reader, yet still technical enough to hold the attention of somebody with more in depth knowledge of previous versions of Flex.
<p>The book also starts out with a nice section on the benefits of Flex and RIA&#8217;s in general along with a few pointers on how to sell upper management on its use.&nbsp; From there they move on to cover the basics of ActionScript and Flex and show how MXML layout works, how MXML and AS work with one another, some basics on how to work with data inside of your application and also detail the differences between the old Halo controls and the new Spark controls.
<p>The second section of the book delves into more complex topics like the event model, view states, writing custom components and more.&nbsp; There is a small jump in the assumed capabilities of the reading audience at this point.&nbsp; Readers who are new to Flex and who have worked through the first part of the book should still be able to follow along at this point.
<p>The only negative that struck me as I was reading the book was the code samples.&nbsp; While they do an excellent job of demonstrating the topic that they are associated with, I would have preferred if by the time I reached the end of the book I had a fully working reference application vs a series of smaller individual apps.
<p>Overall, I enjoyed reading the book and learned quite a lot, not only about Flex 4, but Flex as a whole.&nbsp; The authors did a good job of keeping the subject matter entertaining and making their various contributions flow seamlessly together.
<p>I would recommend this book both to people who are staring out in Flex development as well as people who are already familiar with Flex and looking to find out what is new in Flex 4.
<p>You can pre-order your copy on <a href="http://web.archive.org/web/20120208145212/http://www.xyzpdq.org/ct.ashx?id=8489c6c4-27ae-4ced-b582-94632ac92474&amp;url=http%3a%2f%2fwww.amazon.com%2fFlex-4-Action-Dan-Orlando%2fdp%2f1935182420">Amazon</a></p>
<p>The post <a href="http://xyzpdq.org/2010/03/review-of-flex-4-in-action/">Review of Flex 4 in Action</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2010/03/review-of-flex-4-in-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OData = Hotness</title>
		<link>http://xyzpdq.org/2010/03/odata-hotness/</link>
		<comments>http://xyzpdq.org/2010/03/odata-hotness/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 22:48:00 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/blog/?p=66</guid>
		<description><![CDATA[<p>Microsoft has officially announced OData.&#160; If you are not aware of what this is, then in a sentence: OData is a queryable REST based interface that exposes your data via AtomPub. To publish a feed, you have to use .Net.&#160; &#8230; <a href="http://xyzpdq.org/2010/03/odata-hotness/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2010/03/odata-hotness/">OData = Hotness</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Microsoft has officially announced <a href="http://www.odata.org">OData</a>.&nbsp; If you are not aware of what this is, then in a sentence: OData is a queryable REST based interface that exposes your data via AtomPub.</p>
<p>To publish a feed, you have to use .Net.&nbsp; However, they have provided client sdk’s for a variety of languages to allow for simple querying of the exposed services and they are working on several more.</p>
<p>I strongly encourage you to check it out.</p>
<p>Partly to give an idea of what is possible, and partly for my own reference, I am going to repost a “cheat sheet” that I found online at <a href="http://blogs.msdn.com/alexj/default.aspx">Meta-Me</a></p>
<h6>The Service:</h6>
<p>It all starts with a Data Service hosted somewhere:</p>
<pre class="prettyprint">http://server/service.svc</pre>
<h6>Basic queries:</h6>
<p>You access the Data Service entities through resource sets, like this:</p>
<pre class="prettyprint">http://server/service.svc/People</pre>
<p>You request a specific entity using its key like this:</p>
<pre class="prettyprint">http://server/service.svc/People(16)</pre>
<p>Or by using a reference relationship to something else you know:</p>
<pre class="prettyprint">http://server/service.svc/People(16)/Mother</pre>
<p>This asks for person 16’s mother.</p>
<p>Once you have identified an entity you can refer to it’s properties directly:</p>
<pre class="prettyprint">http://server/service.svc/People(16)/Mother/Firstname</pre>
<h6>$value:</h6>
<p>But the last query wraps the property value in XML, if you want just the raw property value you append $value to the url like this:</p>
<pre class="prettyprint">http://server/service.svc/People(16)/Mother/Firstname/$value</pre>
<h6>$filter:</h6>
<p>You can filter resource sets using $filter:</p>
<pre class="prettyprint">http://server/service.svc/People?$filter=Firstname&nbsp; eq ‘Fred’</pre>
<p>Notice that strings in the filter are single quoted.</p>
<p>Numbers need no quotes though:</p>
<pre class="prettyprint">http://server/service.svc/Posts?$filter=AuthorId eq 1</pre>
<p>To filter by date you have identity the date in the filter, like this:</p>
<pre class="prettyprint">http://server/service.svc/Posts?$filter=CreatedDate eq DateTime’2009-10-31′</pre>
<p>You can filter via reference relationships:</p>
<pre class="prettyprint">http://server/service.svc/People?$filter=Mother/Firstname eq ‘Wendy’</pre>
<p>The basic operators you can use in a filter are:</p>
<table class="table table-striped">
<tbody>
<thead>
<tr>
<th>Operator</th>
<th>Description</th>
<th>C# equivalent</th>
</tr>
</thead>
<tbody>
<tr>
<td>eq</td>
<td><b>eq</b>uals</td>
<td>==</td>
</tr>
<tr>
<td>ne</td>
<td><b>n</b>ot <b>e</b>qual</td>
<td>!=</td>
</tr>
<tr>
<td>gt</td>
<td><b>g</b>reater <b>t</b>han</td>
<td>&gt;</td>
</tr>
<tr>
<td>ge</td>
<td><b>g</b>reater than or <b>e</b>qual</td>
<td>&gt;=</td>
</tr>
<tr>
<td>lt</td>
<td><b>l</b>ess <b>t</b>han</td>
<td>&lt;</td>
</tr>
<tr>
<td>le</td>
<td><b>l</b>ess than or <b>e</b>qual</td>
<td>&lt;=</td>
</tr>
<tr>
<td>and</td>
<td>and</td>
<td>&amp;&amp;</td>
</tr>
<tr>
<td>
<p>or</p>
</td>
<td>or</td>
<td>||</td>
</tr>
<tr>
<td>
<p>()</p>
</td>
<td>grouping</td>
<td>()</td>
</tr>
</tbody>
</thead>
</table>
<p>There are also a series of functions that you can use in your filters if needed.</p>
<h6>$expand:</h6>
<p>If you want to include related items in the results you use $expand like this:</p>
<pre class="prettyprint">http://server/service.svc/Blogs?$expand=Posts</pre>
<p>This returns the matching Blogs and each Blog’s posts.</p>
<h6>$select:</h6>
<p>Some Data Services allow you to limit the results to just the properties you require – aka projection – for example if you just want the Id and Title of matching Posts you would need something like this:</p>
<pre class="prettyprint">http://server/service.svc/Posts?$select=Id,Title</pre>
<p>You can even project properties of related objects too, like this:</p>
<pre class="prettyprint">http://server/service.svc/Posts?$expand=Blog&amp;$select=Id,Title,Blog/Name</pre>
<p>This projects just the Id, Title and the Name of the Blog for each Post.</p>
<h6>$count:</h6>
<p>If you just want to know how many records would be returned, without retrieving them you need $count:</p>
<pre class="prettyprint">http://server/service.svc/Blogs/$count</pre>
<p>Notice that $count becomes one of the segments of the URL – it is not part of the query string – so if you want to combine it with another operation like $filter you have to specify $count first, like this:</p>
<pre class="prettyprint">http://server/service.svc/Posts/$count?$filter=AuthorId eq 6</pre>
<p>This query returns the number of posts authored by person 6.</p>
<h6>$orderby:</h6>
<p>If you need your results ordered you can use $orderby:</p>
<pre class="prettyprint">http://server/service.svc/Blogs?$orderby=Name</pre>
<p>Which returns the results in ascending order, to do descending order you need:</p>
<pre class="prettyprint">http://server/service.svc/Blogs?$orderby=Name%20desc</pre>
<p>To filter by first by one property and then by another you need:</p>
<pre class="prettyprint">http://server/service.svc/People?$orderby=Surname,Firstname</pre>
<p>Which you can combine with <b>desc</b> if necessary.</p>
<h6>$top:</h6>
<p>If you want just the first 10 items you use $top like this:</p>
<pre class="prettyprint">http://server/service.svc/People?$top=10</pre>
<h6>$skip:</h6>
<p>If you are only interested in certain page of date, you need $top and $skip together:</p>
<pre class="prettyprint">http://server/service.svc/People?$top=10&amp;$skip=20</pre>
<p>This tells the Data Service to skip the first 20 matches and return the next 10. Useful if you need to display the 3rd page of results when there are 10 items per page.</p>
<p><b>Note:</b> It is often a good idea to combine $top &amp; $skip with $orderby too, to guarantee the order results are retrieved from the underlying data source is consistent.</p>
<h6>$inlinecount &amp; $skiptoken:</h6>
<p>Using $top and $skip allows the client to control paging.</p>
<p>But the server also needs a way to control paging – to minimize workload need to service both naive and malicious clients – the OData protocol supports this via <a href="http://blogs.msdn.com/astoriateam/archive/2009/03/19/ado-net-data-services-v1-5-ctp1-server-driven-paging.aspx">Server Driven Paging</a>.</p>
<p>With Server Driven Paging turned on the client might ask for every record, but they will only be given one page of results.</p>
<p>This as you can imagine can make life a little tricky for client application developers.</p>
<p>If the client needs to know how many results there really are, they can append the $inlinecount option to the query, like this:</p>
<pre class="prettyprint">http://server/service.svc/People?$inlinecount=allpages</pre>
<p>The results will include a total count ‘inline’, and a url generated by the server to get the next page of results.<br />This generated url includes a $skiptoken, that is the equivalent of a cursor or bookmark, that instructs the server where to resume:</p>
<pre class="prettyprint">http://server/service.svc/People?$skiptoken=4</pre>
<h6>$links</h6>
<p>Sometime you just need to get the urls for entities related to a particular entity, which is where $links comes in:</p>
<pre class="prettyprint">http://server/service.svc/Blogs(1)/$links/Posts</pre>
<p>This tells the Data Service to return links – aka urls – for all the Posts related to Blog 1.</p>
<h6>$metadata</h6>
<p>If you need to know what model an OData compliant Data Service exposes, you can do this by going to the root of the service and appending $metadata like this:</p>
<pre class="prettyprint">http://server/service.svc/$metadata</pre>
<p>This should return an <a href="http://download.microsoft.com/download/B/0/B/B0B199DB-41E6-400F-90CD-C350D0C14A53/%5BMC-EDMX%5D.pdf">EDMX</a> file containing the conceptual model (aka EDM) exposed by the Data Service.</p>
<p>The post <a href="http://xyzpdq.org/2010/03/odata-hotness/">OData = Hotness</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2010/03/odata-hotness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ColdFusion Troubles</title>
		<link>http://xyzpdq.org/2010/02/coldfusion-troubles/</link>
		<comments>http://xyzpdq.org/2010/02/coldfusion-troubles/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 22:49:00 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[Cold Fusion]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/blog/?p=67</guid>
		<description><![CDATA[<p>I have been running awry of ColdFusion. I am running Windows XP (not by choice), and *had* a local installation of ColdFusion 8 Server.&#160; The instance of ColdFusion was stopped since it is a bit of a memory hog and &#8230; <a href="http://xyzpdq.org/2010/02/coldfusion-troubles/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2010/02/coldfusion-troubles/">ColdFusion Troubles</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I have been running awry of ColdFusion.
<p>I am running Windows XP (not by choice), and *had* a local installation of ColdFusion 8 Server.&nbsp; The instance of ColdFusion was stopped since it is a bit of a memory hog and I was not actively using it.&nbsp; I have been working on getting an instance of Telligent Community Server up and running for evaluation purposes.&nbsp; I was baffled by the fact that the Telligent demo was taking around 10 minutes on average to load a page from the local system.&nbsp;
<p>Needless to say, since everything else seemed to be running fine, I was blaming Telligent’s software.&nbsp; Then I started exploring a little more and figure out that IIS was taking around 30 seconds just to serve up an image.&nbsp; Something was definitely up, but despite all of my best troubleshooting skills, I could not source the problem.
<p>I did what I always do when something goes wrong that I don’t understand, I turned to Google.
<p>I tried about 20 different “solutions” until I stumbled across a forum post saying to start ColdFusion if it was installed.&nbsp; *poof*. The page that took 10 minutes to load before now takes 5 seconds.&nbsp; It turns out that the CF ISAPI plugin is constantly trying to talk to the server.&nbsp; If it can’t find the server, it doesn’t just die, it keeps trying. … on every. single. request.
<p><strike>strike one.</strike>
<p>A short while later, I was working on trying to speed up a dashboard application that&nbsp; coworker and I had written.&nbsp; It is pretty simple. CF queries the database and retrieves somewhere in the range of 10-700 rows of data, turns them into objects, passes those objects off to Flex which then graphs the objects.&nbsp; It was performing fine as long as there was less than 40 rows. By the time you got up to a few hundred rows of data, it would take an obscene amount of time to load.
<p>We scratched our heads for the longest time and were pretty convinced that the Flex chart control was to blame.
<p>Then we had an idea.&nbsp; Instead of letting CF instantiate each row into an object, just send CF the results as an XML document from the database, let CF hand the XML off to Flex, and then proceed from there.
<p>Same story. 10 minutes now became 2 seconds.
<p>It seems that ColdFusion doesn’t do so well at creating objects.
<p><strike>strike two.</strike>
<p>I’m not very pleased with ColdFusion at the moment.</p>
<p>The post <a href="http://xyzpdq.org/2010/02/coldfusion-troubles/">ColdFusion Troubles</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2010/02/coldfusion-troubles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Response.Redirect inside of a Try/Catch</title>
		<link>http://xyzpdq.org/2009/03/response-redirect-inside-of-a-trycatch/</link>
		<comments>http://xyzpdq.org/2009/03/response-redirect-inside-of-a-trycatch/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 22:49:00 +0000</pubDate>
		<dc:creator>cbeckner</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>

		<guid isPermaLink="false">http://xyzpdq.org/blog/?p=68</guid>
		<description><![CDATA[<p>Ok, first off, let me state, that I am not entirely certain WHY I did this in the first place.&#160; I am going to say I was rushed and wasn’t thinking clearly.&#160; However, I glazed over it and moved on &#8230; <a href="http://xyzpdq.org/2009/03/response-redirect-inside-of-a-trycatch/">Continued</a></p><p>The post <a href="http://xyzpdq.org/2009/03/response-redirect-inside-of-a-trycatch/">Response.Redirect inside of a Try/Catch</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Ok, first off, let me state, that I am not entirely certain WHY I did this in the first place.&nbsp; I am going to say I was rushed and wasn’t thinking clearly.&nbsp; However, I glazed over it and moved on and when it came time to test, I was getting bizarre behavior that didn’t throw an error.</p>
<pre>Session[“var”] = “”; 

try 
{ 
    Session[“var”] = “Good Value”;

    Response.Redirect(“newpage.html”); 
} 
catch(Exception ex) 
{ 
    Session[“var”] = “Bad Value”; 
}</pre>
<p>In the code above, Session[“var”] will ALWAYS equal “Bad Value”.&nbsp; Why you may ask?</p>
<p>Response.Redirect throws a ThreadAbortException.&nbsp; … Fun, no?</p>
<p>If you are building a URL inside of a try block that you want to then redirect to, declare a string, build your url, and then pass that on to the Response.Redirect statement.&nbsp;
<p>For Example:</p>
<pre>string _url;

try 
{ 
    _url = “yourpage.aspx?var=” + iffyMethodCall(); 
} 
catch(InvalidOperationException ex) 
{ 
    _url = “error.html”; 
}

Response.Redirect(url);</pre>
<p>So, If you ever run into odd behavior in a site you are working on and when debugging, your code goes straight past your Response.Redirect and into the catch block and the debugger starts giving you cryptic messages, this may be what you’re seeing.</p>
<p>The post <a href="http://xyzpdq.org/2009/03/response-redirect-inside-of-a-trycatch/">Response.Redirect inside of a Try/Catch</a> appeared first on <a href="http://xyzpdq.org">XYZPDQ</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://xyzpdq.org/2009/03/response-redirect-inside-of-a-trycatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
