A very good tutorial on how to use Code Snippets, I highly recommend that you check out this feature so that you can reduce the amount of time you spend typing in order to increase the amount of time that you spend doing other things... Like thinking?
CodeProject: Object ByteArray Converter.
A very useful class, especially if you need to somehow store objects in a persistent way. This allows you to convert anything (object) to a byte[] (byte array) and from a byte[] (byte array) to anything (object).
CodeProject: Object ByteArray Converter. Free source code and programming help
Writing a Provider for ASP.NET
When I started programming, some 20 years ago (damn, I feel old now) - we didn't have as many "toys" and "gadgets" as we do today. To be honest, back then, computer programming was so new that the most successful programmers were the ones that were able to use imagination to solve problems.
Today, things are very different. We have very solid Integrated Development Environments (IDEs) along with a myriad of best practices such as Design patterns.
I remember when OOP first came out, it was such a revolution that it even got some ink in newspapers (and not even in the tech section, but in the general section). Little did we know back then that OOP was still in its infancy and would evolve into what it is today where we would apply Patterns such as the Strategy Pattern and the Singleton Pattern.
While designing a good architecture with OOP is a very good idea, there is another pattern that I would like to discuss today: The Provider Pattern in ASP.NET.
A provider is essentially a window into some functionality. For example, I could design a Provider that handles authenticating users:
The Authentication Provider
What's clear about designing a provider is not to stop at the how but instead looking at the what.
Think about it this way:
- How things work
- What you want to do
How things work: Are we using this technology or that one? Are we using SQL to authenticate users or LDAP? Or maybe we will be using XML files, or perhaps another system such as a custom Web Service.
Beginning with Providers
Proper programming usually starts with admitting that you are trying to solve a problem, and not trying to see how you can justify using this cool technology and use it to try to solve a problem. So we aren't going to look at the What yet and instead look at the How
| How | What |
| We want to authenticate users, we want to get their e-mail address, we want to get their full name, we want to know if their account is active, etc | Connect to SQL server, open an XML file, open an HTTP channel to a Web Service, open an LDAP connection to a Directory Server |
A bit of philosophy on WiFi
Years after the aftermaths of Chernobyl we can now fully appreciate all of the side effects of radiation and their long-term effects.
What people don't seem to understand is that a Microwave essentially cooks by a form of radiation.
Therefore, Radio waves, are a form of radiation.
Therefore, WiFi uses radiations to carry our information?
Radiowaves can alter skin tissue with RF Burns.
Interesting.
Let's make a few assumptions then:
Radiations can make you sterile, they can also alter foetus development. Are technology-savvy countries starting a process that will eventually lead to us having a population that cannot bear children? With all of our cell phones, WiFi devices like MP3 players, Bluetooth headsets, remote car starters and door locks. What effect are all those devices having on all of us?
Well, it's plausible that if it continues North America won't be able to produce viable embryos, if that is the case then we won't get any more kids. If we don't have any more children then what is the next step? Are countries like China and continents like Africa going to become the baby-producing factories of the planet? Are those areas of the planet going to position themselves as the baby factories of the planet, basing their entire economies on North America's own self-induced disease?
It wouldn't be the first time in history this happens.
I remember seeing a movie where would-be parents go to baby markets and get to pick out their babies - I guess the price for blond, blue-eyed babies if going to go through the roof while the other kids go for a lower price.
It's an amusing thought, but it's also a scary one as it's not that far from reality.
Error CS0227: Unsafe code may only appear if compiling with /unsafe
This was an easy fix but a nasty little problem.
Background: You compile on your machine and the world is good. You check in your code and the TFS/Build machine finds errors in your code and tells you that you can only compile if you use the /unsafe option. But, you already selected that option.
Cause: You have not checked the "Allow unsafe code" checkbox in the project properties for the current compilation configuration.
Programmer: I have checked that box, see?
The big trick here is most coders will compile only in the "DEBUG" world and not in the "RELEASE" world. If you go to your project properties, under build, and then select the "All Configurations" Configuration (dropdown, top left) and then select the "Allow unsafe code" from that configuration option.
What happens here is that the usual configuration for the build server is to compile with the release configuration, which coders usually omit to configure.
That's why I love TFS and my BUILD server. They are my coder traffic cops and catch those pesky mistakes that humans do.
Fighting IIS - Site Under Construction - KO
In the last 7 days, I've seen a very peculiar problem come and go.
Turns out that VPN was the whole problem.
In our problem, we were getting a "Site under construction" page every once in a while for a client trial system. We couldn't figure it out.
Legitimately, the client himself was starting to doubt in our capabilities - and I can understand them.
Thanks to a quick chat with one of our programmers, we found the problem - he was asking me what IP address we obtain when we VPN into the remote network.
Duh! That was the whole problem. When we VPN into our remote network, ISA has a collection of 10 IP addresses that it can give out, it turns out that the two addresses that I gave that site last week (business is picking up) was actually overlapping the VPN addresses.
We have systems that periodically connect to the remote client network to pick up data and perform automated work. Well, one of those systems is our backup e-mail system. No, it doesn't have a default web site - it shows as "Site under construction".
When this system connected, once in a blue moon it would get the server's IP address - then since ISA gets the incoming request and also handles the VPN, it would simply forward the client request to the new remote-remote system, the mail server checking into the backup.
We have changed the pool of VPN IPs to a different set, which should allow us to grow with at least another 150 clients before we have to change the pool again. I hope that our client trial goes well. I'm not going to tell them that it's fixed yet since I've done that a few times before and it turned out I was wrong, I'm going to let the day go by and then we shall sit down and have a quick talk where I'll explain what the problem was.
I was right on one count, it wasn't our product that was going down. The culprit was the network infrastructure.
Fighting IIS - Site Under Construction
We have an ASP.NET Application, newly installed, under a load of no more than 20 concurrent users. Every once in a while, this application isn't served by the web server (IIS6), instead it displays a "Site Under Construction" page.
Our default web on the machine does indeed have this page, however the default virtual web is stopped. We use IP addresses to publish websites, so it's not like you can actually mess this up. It's essentially the same IIS configuration that I've done for the last 8 years starting with IIS4.
Virtual web server published through a private unique IP, no host header or any other fancy thing going on. The firewall (ISA) takes care of handling the public request and is programmed to route to the private IP.
Everything was installed and the world was good until the first instant the server came under load (about 10+ concurrent users) and then we saw the "Site Under Construction" page.
Verifying the firewall logs shows the obvious, the remote users are coming in to the site and are being routing to the proper IP address.
Verifying the web server logs tells a different story, when the site is "under construction" then it seems that according to the log the actual requests never make it to the server.
What does this mean? Requests are sent from the firewall and are being served by a web server, just not the intended one.
After spending 3 hours with Microsoft Support on the phone, we have decided to change the IP address (private) of the server and reconfigure the firewall to the new private IP address. We shall then see what happens on Monday morning.