If you are at home and somebody knocks on your door, don't ignore it. It's also a bad idea to blindly open the door. Look and see who it is first, preferably from your peephole in the door or somewhere the person at the door can't readily see you. Get a good look at them.
Then STEP AWAY FROM THE DOOR (and preferably to the side) and shout. I've used everything from "Who is it?" to "Go away!", but the point is to say something so whoever it is doesn't assume the house is unoccupied. If you don't want to shout, switch the porchlight on and off or something. If you can get one, install an intercom and interview the person that way.
I can also tell you that it's a common practice, at least among rural folks and police officers, to arm yourself first. By that I don't mean to point a gun at them, just to have one on you. One way to do this is to hold the pistol in your dominant hand, hold that arm close to your side, and sort of hold the pistol behind your thigh.
Ok, I didn't describe that very well, so here's a picture. If you hold it this way, you're not scaring the bejeezus out of some salesperson, and you can still shoot a bad guy if it proves necessary.
Depending on your visitor you may choose to open the door. If it's a friend, I usually holler "just a second!" and get the gun out of my hand. If something seems odd, or if it's a stranger I don't. Up to you.
Now I have a steel security door over my front door so I can talk to strangers through that, without opening the front door all the way. If you don't, at least put the chain on. If you have neither, I don't know what to tell you. Maybe to brace your foot against the inside of the door so it won't open more than a couple inches, so the other person can't just barge in. Keep in mind that if they try to push past you this may knock you off balance.
If you don't want to open the door and the person refuses to leave, tell them politely that they're trespassing, and tell them you're calling the cops. Depending on the circumstances, you may choose to punctuate this by racking a round into the shotgun. That's universally understood, but if you don't have one try hitting your car alarm.
The point is to develop some situational awareness- opening the door can be dangerous and unexpected guests may not choose to go away quietly if you ignore them.