It's not possible to prevent a browser from connecting to your site using an IP address. After all, for this purpose, the DNS system is simply a friendly name layer on top of IP addresses.
The only thing you can really do is filter the URLs that are presented to your web server. While you can certainly do this at the application layer, you're far better off using the capabilities already built into your web server for doing this.
I assume you're using IIS based on the link you posted. Any good reason for not using the built-in capability to accomplish what you want?