Reading an octet stream post in ASP.NET

I'm using Adobe Flex to take a snapshot of some controls. I turn the PNG encoded bitmap data into a ByteArray. I then send the data to the server, through an ASP.NET page. On the Flex side of things, I send the data over with the following code:

var req:URLRequest = new URLRequest();
req.method = URLRequestMethod.POST; =;
req.url = "snapshotuploadhandler.aspx";

var loader:URLLoader = new URLLoader; loader.load(req);

I assumed this code was incorrect, but it was actually the code in the receiving page. Instead of checking the "Files" property on the request object, I needed to read the InputStream on the request. Here is the working code:

if (Request.ContentLength > 0)
    byte[] buffer = new byte[Request.ContentLength];
    using (BinaryReader br = new BinaryReader(Request.InputStream))
        br.Read(buffer, 0, buffer.Length);
    return buffer;

Like this post? Please share it!

See a mistake? Edit this post!

I switched from Linux to Windows Server 2008

Wait, did I say that right? I thought it was supposed to be the other way around?

I admit it, I loved running Ubuntu Server 64-bit on my VMware server. It ran very amazingly fast, and I didn't have to touch it for months. I also liked the idea of all of the configuration being text based. It was easy to backup and restore.

Ubuntu Linux

There were just a couple of recurring issues that made me uneasy. The console screen would randomly display network adapter issues, and sometimes I would lose the network connection until I would restart the networking script.

The other issue is that my software RAID 1 array would randomly disappear on reboot. I would have to run this command to fix it:

sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 --assume-clean /dev/sd[ab]

The last major issue I had was with the VMware Server installation. Out of the gate, the installation was 10 times more difficult. It wasn't a click->next->next->next install. Once I got it installed, the VMware server console wouldn't connect.

Windows Server 2008

Since Windows Server 2008 has been released, I've heard nothing but amazing things. This is the best operating system to come out of Microsoft for a long time. For about the past month, I've been trying it out on my laptop. It's basically Vista x64 SP1 without all of the crap. Microsoft really messed up Vista, but somehow they managed to fix it in their server product.

Installation took less than 15 minutes, and I appreciate the fact that it doesn't ask you anything other than the location to install to. It boots extremely fast, and is impressively snappy.

All of the previous issues I mentioned have gone away (I cheated on the RAID problem, since I'm not using RAID anymore).

The most frustrating thing about Linux (and one of it's biggest strong points), is that I never had a really good GUI tool to fall back on when things got rough. When something goes wrong in Windows, I can at least look around at my options. In Linux, you have to look at documentation and examples, and guess what the syntax and settings are for your configuration.

The biggest problem for many of my readers is going to be the fact that you can't get a copy of Server 2008 for a reasonable price. In my case, this is a development server, and I'm able to use my MSDN (Microsoft Developer network) license.

A common question I'm asked, is if I had any problems finding drivers. Every driver I needed was automatically installed by Windows. It's very impressive seeing as how it's a completely custom server, with all of the parts purchased on NewEgg.

I still love Linux, but right now I'm more productive with Windows Server 2008 x64.

Update Apr. 18, 2008: I posted a follow-up to this post here

Like this post? Please share it!

See a mistake? Edit this post!

ASP.NET output caching by user agent

I received this question from ObiShawn:

"Does .NET/IIS output caching vary by user-agent?"

Good question Shawn! By default, the output cache stores the same version of the page for all users, regardless of their user agent. To change this behavior, add the VaryByHeader parameter to your OutputCache declaration:

<%@ OutputCache Duration="60" VaryByParam="*" VaryByHeader="User-Agent"  %>

This is probably a good idea to include in your OutputCache directive, because ASP.NET will render controls differently to some browsers.aspx). It modify the output HTML based on the browsers capabilities.

If your site is only targeting the latest generation of browser, you can probably avoid varying by user agent.

One last note. You can include multiple headers in the VaryByHeader parameter. Simply separate them with semi-colons.

For more information about OutputCaching, this is a great article.

Like this post? Please share it!

See a mistake? Edit this post!

Jason Young I'm Jason Young, software engineer. This blog contains my opinions, of which my employer - Microsoft - may not share.

@ytechieGitHubLinkedInStack OverflowPersonal VLOG