If you're a bit organized and plan your drinking, you can take the multi-pronged approach of before, during, after.
Before drinking, eat a good meal, as someone else here said, rich in fats and carbs. Drink plenty of water.
During drinking, consume water and avoid cheap booze (which is often artificially fortified with alcohol and likely contains chemicals and impurities which will make hangover much worse). Pace your drinking - you want to get drunk, presumably, not make yourself sick.
After drinking but before going to bed, dissolve a packet of electrolyte salts in a glass of water and drink it. Most of a hangover is severe dehydration, and most of dehydration is electrolyte depletion; so replenish water and electrolytes before the problem occurs. Take a B-complex tablet and Vitamin C. This is really key. These vitamins are proven to do wonders for preventing hangover.
If you feel hungover when you wake up, have a breakfast rich in carbs and fats. Drink coffee. The caffeine will reduce swelling of blood vessels and thus lessen your headache. (Don't drink too much, though, as too much could make the headache worse.) Once you have something in your stomach, take the vitamins again. Have another glass of water with electrolyte salts. Stand in a hot shower or sit in a sauna to loosen tense muscles. Get some exercise.
Good as new. If you forget the before part, do the during and after. If you forget both before and during, you're screwed, but you can still minimize the hangover by doing the after bit.