I had a Vet tell me to use a spray bottle w/small amt of white vinegar in it. When your pet is someplace you prefer it not to be, lightly spray the pet and give a harsh command (no no, etc)
They do not like the smell or the spray in their face.
Soon, it will learn that just the sight of the spray bottle will be an unpleasant experience and that will be enough! Eventually, in theory anyway, the pet will know where it is NOT allowed.
(white vinegar has no ill affects).
Good Luck!!!!