Archive for April, 2008

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.data = snapshot.data;
req.contentType="application/octet-stream";
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;
}

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

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. 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.

Ask me questions, I might just answer!

On the right side of my blog, you’ll notice that I added a question button. If you have a question that is technology or software related, please ask! If your question is stupid, I admit, I will probably ignore it. However, if you have a good question, I’ll try my best to answer it with its very own blog post.

I'm Listening

A former co-worker of mine mentioned that he doesn’t have a contact page because he’s afraid of the questions he’ll get. I know exactly where he’s coming from. I’m hoping that every once and a while there will be a jewel in there and we can both benefit. Of course if I choose your question you’ll get a link from this blog, and all the fame and fortune that comes with it.

On a side note, I got the cool looking dialog below when I went to delete the question mark image off my computer. I think Windows would be a lot cooler if they bought some images off of iStockPhoto.

Delete File Dialog

DataSet XML serializer utility for unit testing

Quite a while ago I wanted to do some unit testing with DataSet’s and DataTable’s as input. In code, there isn’t really an easy way to generate them, especially if you want them to be a realistic subset of the real data in your database.

My solution was to build a program that acted like SQL Server’s Management Studio, but who’s output is a serialized DataSet. The resulting XML can simply be embedded into your unit test project. In your unit test, you simply deserialize the DataSet XML into a DataSet.

DataSet XML Serializer

Is anyone interested in me posting the source code and compiled EXE? I’ll have to clean it up a bit, so I wanted to see if there was enough interest, of if it’s something I’ll just keep using in-house.