Restrict IP Address in ASP.NET Web API

There are several ways to restrict access to a Web server based on the requestor’s IP address either from IIS or using inbound Firewall rules. But If you want to restrict access to one of the applications deployed in the server based on the IP Address then you have to achieve that programmatically.

Get the incoming IP Address:

The method for getting IP address from the request varies depends on the hosting method. The following method gets the IP address from the request message, if the hosting method is any of the following three

  • OWIN Hosting
  • Web Hosting
  • Self Hosting


Please refer the following links for more details

ASP.NET Web APIhttps://www.blogofpi.com/restrict-ip-address-in-asp-net-web-api/

ASP.NET Core Web APIhttps://www.blogofpi.com/restrict-ip-address-asp-net-core-web-api/


No Comments