locked
Is it possible to configure a location in Web.config to deny all my country except my ip and also allowing the rest of the world? RRS feed

  • Question

  • User-1010484996 posted

    I've got a page in an ASP.Net app and I would like to deny connections from my country but allowing my personal ip to this page from the local machine. Anyone know if this is possible?

    Thanks!

    Tuesday, March 26, 2019 3:46 PM

All replies

  • User-1174608757 posted

    Hi ayhesahinds,

    According to your description, if you want to block your connection to your Asp.net app, firstly you should get the specific ip address  of your country,then you could set the block of ip address in web configure file , then  application will deny all the connections from ip address you set.

    To get the ip address of your country , you could see in the link as below:
    https://en.wikipedia.org/wiki/List_of_countries_by_IPv4_address_allocation

    You could write below code in web configure file.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <system.webServer>
    
         <security>
          <ipSecurity allowUnlisted="false">  <!-- line blocks everyone, except  below IP -->
             <clear/>
    
             <add ipAddress="83.125.18.53" allowed="true"/>  <!-- allow the specific IP of 83.125.18.53  -->
             <add ipAddress="83.125.18.0" subnetMask="255.255.255.0" allowed="true"/>  <!--allow network 83.125.18.0 to 83.125.18.255-->
         </ipSecurity>
       </security>
    </system.webServer>
    </configuration>

    Here is the link,  I hope it could help you.

    https://blog.arvixe.com/using-web-config-to-allowdeny-access-to-an-specific-ip/

    Best Regards

    Wei

    Wednesday, March 27, 2019 2:09 AM
  • User465171450 posted

    The problem is your country won't have a single set of IP addresses most likely. They will be a number of ranges of varying sizes and could be from many different networks. There's no real good way to do this and this also doesn't really increase your security as blocking an ip should really be done at the server level.

    Wednesday, March 27, 2019 3:24 AM
  • User1120430333 posted

    I've got a page in an ASP.Net app and I would like to deny connections from my country but allowing my personal ip to this page from the local machine. Anyone know if this is possible?

    Thanks!

    No, you cannot do it, which would take you blocking a range of IP(s) like maybe like 100,000 most likely  much more range of IP(s). You can do it wit a firewall router or firewall appliance.

    Wednesday, March 27, 2019 3:43 AM
  • User-1010484996 posted

    Thanks, I tried that method and it did not work =(

    Wei Zhang

    Wednesday, March 27, 2019 12:46 PM
  • User-1010484996 posted

    Thanks markfitzme

    Wednesday, March 27, 2019 12:48 PM
  • User-1010484996 posted

    Thanks, i will try by firewall appliance 

    DA924

    Wednesday, March 27, 2019 12:49 PM