Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi
I'm in big trouble, I have created a website and the I want the website to be opened by only certain IPs. And also i want to restrict the website from indian IPs. I have done the website in c# ASP.NET and hosted the website to Windows 2003 server. I found some thing with .htaccess, i tried it but now working. I'm not sure what is the problem.

Can any one tell me how to do this?

Thanks and regards
Nidhin
Posted

Try using this
Add the below lines in web.config file

XML
<system.webServer>
      <security>
        <ipSecurity allowUnlisted="true">    <!-- this line blocks everybody, except those listed below -->
           <clear/> <!-- removes all upstream restrictions -->
           <add ipAddress="83.116.19.53"/>   <!-- block one IP  -->
           <add ipAddress="83.116.119.0" subnetMask="255.255.255.0"/>   <!--block network 83.116.119.0 to 83.116.119.255-->
        </ipSecurity>
      </security>
      <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>



Check this Link
http://boseca.blogspot.com/2010/12/programmatically-addremove-ip-security.html[^]
 
Share this answer
 
v2
Comments
Dalek Dave 14-Sep-11 3:50am    
Nice!
The simplest way is to add code to your Master CSS page Load event, which checks if the IP address of the caller is acceptable, and redirects to a "forbidden access" page instead if necessary:
C#
string ip = Request.UserHostAddress;
if (IsNotAllowedIP(ip))
   {
   Response.Redirect(@"~/NotAllowedAccess.aspx", true);
   }
else
   {
   ...
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900