Posts tagged 'vb.net'

Base32 Encoding and Decoding in VB.NET

Like the more common Base64 encoding, Base32 encoding is a method for turning binary data into a string composed of a small, defined set of ASCII characters. Base64 takes advantage of the entire alphabet in both upper and lower case, the digits 0 to 9 and the '+' and '/' symbols. This can be problematic where, for example, the encoded data needs to be used as part of a URL where the '+' and '/' symbols have special meaning and where case-sensitivity can cause problems.

Base32 addresses these issues by using a further reduced set of characters - the entire alphabet (but only one case) and the digits 2 to 7. The digits '0' and '1' are ommitted due to their similarity to the letters 'O' and 'I'. This makes Base32 even more useful in situations where human readability is a concern.

More information about Base32 can, of course, be found on the Base32 Wikipedia page.

continue reading >
7 August

PNG Colour Rendering on the Web

When is a colour not a colour? When it's in a PNG image file and you want to display it in a web browser!

I have recently been working on a website which includes a number of PNG images which are generated at run-time by a piece of VB.NET code. During testing we noticed a number of discrepancies between the colours being rendered in the image and the colours specified in the site's CSS file.

To make matters worse, the behaviour varied from browser to browser. Google Chrome behaved as desired - a perfect colour match. Internet Explorer appeared to render the colours in the PNG darker than we wanted. When we tried Firefox, the colours in the PNG were rendered with a different shade of the desired colour (a slightly purple tinge to our desired blue, in our case).

continue reading >
10 October

Automatically switching to SSL in ASP.NET

At first, it seems like quite a simple requirement - to automatically transfer a visitor to an SSL connection when they visit a certain area of our site (everything in the 'secure' folder in our case), and to transfer them back to a plain old HTTP connection when they leave.

Our initial implementation of this was a simple HTTP Module. This intercepted incoming HTTP requests for the '/secure/' folder and redirected the user to an HTTPS version of the same page. Conversely, if an HTTPS request comes in for a page which isn't in the '/secure/' folder, a redirect is issued to the HTTP version.

This appeared to work fine for quite a while. But - we started to have some problems with the release of IE8 and recent releases of Firefox. On visiting the site, it would appear that requests for WebResource.axd were still being issued over HTTP rather than HTTPS. This meant that our users started getting warning messages pointing out that some parts of the page were not being delivered securely.

continue reading >
1 August

Saving processor time AndAlso writing tidier code, OrElse!

Every once in a while, you stumble across something new and you wonder how you ever survived before you found it. This happened to me most recently when I came across the AndAlso and OrElse operators in VB.NET.

The official description of the AndAlso operator from Microsoft is that it "Performs short-circuiting logical conjunction on two expressions".

What does this mean? The 'logical conjunction on two expressions' means that it basically performs the same task as a standard logical 'And':

continue reading >
9 October