Pretending they don't exist, which entails not making eye contact, not walking faster, not saying 'hello' or 'no', will often humiliate them or tire them out without frustration on your part.
To avoid being held hostage by a mercenary taxi, keep your luggage with you on the back seat so you can credibly threaten to walk out and not pay.
They'll usually back down by the time you start opening the door — and if they don't, get a new driver.
Your driver or guide will tell you that the place you're heading to is closed, no good or too expensive and that he knows somewhere better.
While this may be true, it's likely that the 'better' place is giving him a commission for referrals, and his commission is just going to increase your room rate.
The best thing you can do is avoid using taxis whenever possible.
Before arriving in a new location have your accommodation pre booked, find out where it is on the map and see if there is alternative transport such as local buses to get to or near your accommodation.
Prevention is based on knowledge: researching your destination will both alert you in advance to scams in the area and let you know what the usual prices and truly good sights are so you will be less reliant on the approaches of helpful individuals when you're vulnerable.
At the same time, if you do get stung, don't be too hard on yourself: you were dealing with people who knew the location a lot better than you and with people who were out to deceive you.
You must insist on going to your planned destination.
In some cases the driver will not drive you to your hotel even if you insist.
Generally, the destination is in fact open for business: simply refuse the offer and go and have a look.