Click here to Skip to main content
13,094,411 members (56,958 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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
Posted 13-Sep-11 21:21pm
Rate this: bad
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);
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

        <ipSecurity allowUnlisted="true">    <!-- this line blocks everybody, except those listed below -->
           <clear/> <!-- removes all upstream restrictions -->
           <add ipAddress=""/>   <!-- block one IP  -->
           <add ipAddress="" subnetMask=""/>   <!--block network to>
      <modules runAllManagedModulesForAllRequests="true"/>

Check this Link[^]
Dalek Dave 14-Sep-11 3:50am

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 14 Sep 2011
Copyright © CodeProject, 1999-2017
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