Category Archives: Joco Library

Storing .NET objects in cookies part 2 – compact bytes to string conversion

As I mentioned in part 1, Forms authentication cookies can get quite big when they have some data in the UserData field. The main problem is that every 8-bit character in the user data occupies four characters in the cookie, because it is UTF-16 encoded (1 character – 2 bytes, an extra zero is added) and converted to a hexadecimal string (1 character – 4 characters). For example, the “X” character (U+0058) ends up as the four character string “5800″. Plus a little overhead of the ticket itself, plus the 33% overhead of Base64 encoding. Here’s how you can do a lot better. Continue reading

Storing .NET objects in cookies part 1 – compact serialization with binary XML

I was recently faced with the following challenge in an ASP.NET application. I have a data contract object that describes a user, which I have to store in a cookie for authentication and other purposes. Forms authentication is perfect for this: the cookie is cryptographically protected, the authentication is very easy to configure and it can store arbitrary user data as well. Problem is, as you might guess, this cookie would be quite big. You might ask, why don’t I store this object in the session? Because I wanted a session-less application. Or why don’t I store only a user ID in the cookie? Because gathering the user information is quite an expensive task. So the challenge was to serialize this object in the most compact way. Continue reading

Directory object dialog in .NET, and advanced COM marshaling

Last week I wanted to start a new .NET project, and I needed a directory object picker for it. I searched the web and found some solutions, but they just didn’t look right and decided that I can do a lot better than those. So in the spirit of creating good and reusable code, I started implementing my own IDsObjectPicker wrapper in my framework. I thought it would be easy, and it turned out to be anything but, but the result was awesome: clean, easy to use, and it works. And just like last time, I learned a lot about COM interop, you can read all about it here, or just scroll through and grab it already. Continue reading

Windows antivirus API in .NET, and a COM interop crash course

Like I said in my previous post, I already coded something cool in my framework, and here it is: .NET code to call the Windows antivirus API. The best use case scenario I can think of is when retrieving and then redistributing file content from an untrusted data source, especially a web upload form. In cases like this, content might slip through the realtime protection of most antivirus products, and an API like the one I created is the only solution. Continue reading

Introducing my open source .NET library

One of my biggest plans has always been to publish source code. I’m a professional developer but it’s also my hobby, or more like my art, and I want to do something useful for the benefit of everyone. I’ve posted code a few times on my previous website, but nothing major or widely usable. The life-changing great idea still has yet to come, but I decided to stop waiting for it and publish whatever minor pieces of software I come up with in my free time. C#/.NET is my language/platform of choice, so I started putting together a library project on Google Project Hosting and license it under the GPL v3. It’s a totally generic collection of library routines that anyone might find useful. So here it is: the Joco Library. Continue reading