The only infidelity you can prevent is your own.
I had the same thoughts, three months before my wife cheated on me she asked me to go to counseling. I didn't refuse, but I did say hat I thought we could just talk about what was bothering her. I was wrong. She was already lying to me about what she was doing when she was with friends, the OM, was just waiting to randomly be met, and she was lying to her doctor as well. It turned out that we went to counseling 7 months later, during which time she had an affair, was drinking heavily when I was not around, was using marijuana in secret, and going "fucking nuts" in her own words later.
Did any of this come up in counseling?
No.
The problem was that nobody knew what her life had been like before she met me, and she was never going to tell that story, even if she killed herself because of how it made her feel.
How do you prevent affairs? Your own, of course. By being honest with yourself, honest with others, and recognizing slippery people and places for what they are.
I'm married. I have a wife and kids. There is a flirtatious woman younger but still near my age, single, attractive, works with me, and has made her interest in me apparent, and she knows I'm married. If I were single, I'd be there.
But, I'm being honest with myself. My family depends on me. I do matter. My faithfulness matters. cheating does hurt others even if they don't know. I know I'm attracted, I know that I'm flattered by her attention, and I know that there is never any good reason for us to ever be alone at any time, anywhere, and that any such steps are infidelity, long before the sex happens.
Of course, I learned all this the hard way.