Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 13-Sep-11 21:21pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
string ip = Request.UserHostAddress;
if (IsNotAllowedIP(ip))
   {
   Response.Redirect(@"~/NotAllowedAccess.aspx", true);
   }
else
   {
   ...
   }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try using this
Add the below lines in web.config file
 
<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[^]
  Permalink  
v2
Comments
Dalek Dave at 14-Sep-11 3:50am
   
Nice!

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

  Print Answers RSS
0 OriginalGriff 392
1 CPallini 365
2 Sergey Alexandrovich Kryukov 348
3 BillWoodruff 264
4 George Jonsson 255
0 OriginalGriff 5,095
1 CPallini 4,285
2 Sergey Alexandrovich Kryukov 3,767
3 George Jonsson 2,941
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 14 Sep 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100