If you prevent an IP from accessing your website you can run into problems because sometimes many people will share the same IP.
For example, say you have a university where many students are connected to a LAN which is connected to the Internet. Any university students that connect to your website will be connected using the same IP: the university's IP.
If you block this IP then many people will be blocked from your site. This is why many websites block users instead of IP addresses.
It's a lot of work cleaning up after people who are abusing your website but that's part of the job.
Now, that being said, you can detect the IP of the user that is connected to your website using the
Request.UserHostAddress. This contains the IP address of the user connected to your webpage.
For example:
-
string ip_address = Request.UserHostAddress;
Happy coding!
-Frinny