FWIW, I think this is a bad idea and will invariably not go well and stop legitimate users from accessing your server, and not keeping all ones that should not access it out. Obviously, I don’t know the background and reasons for why you want or need to implement this check, but consider your users might be traveling abroad, using a VPN while being in the correct country, or merely on a new ISP you haven’t whitelisted yet, for example.
We give financial services, our clients are only allow to access our software in the offices that are register to give the service to our final customers (like a franchise), they don’t allow to move their desktop equipment to other location or copy the app to other equipment, and the condition is that they access from public IPs. (Not dynamic). We had several incidents where the equipment is move to another location, or get robbed, o somebody try to copy the software to another machine and access to other location. We are a money remittance service with many agents. This can make clear our necessity.
Another option, and maybe somewhat more maintenance-friendly, would be to use a firewall before your server to block the IPs? That’s what I have seen recommended generally for this cases, and it makes sense to have something specifically made to work as a gateway between the outside world and your services, instead of trying to implement that kind of layer inside your own app.
Mind you, you can certainly have both.
You can use directly the Windows Firewall, specially if you only want access from specific IPs, or some other firewall software, pfSense is one I’ve seen mentioned regularly, but I am sure there will be a lot of options.
You are right, that is other possibility, the thing is that for the operators, is very friendly to have de permitted IPS on a database, and not to access the firewall.