Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Security by IP in ASP 1

Status
Not open for further replies.

ElEye

IS-IT--Management
Nov 17, 2001
187
US
Greetings, Gurus:

I need to allow some .ASP pages to only show to users of certain IPs. I cannot use the IIS security for this since some pages would have this protection, but others not.

Ideally I could just have a line of code for each IP I wish to include.

Thank you! Dave [idea]
[]
 
Use Request.ServerVariables("REMOTE_ADDR") to get the IP address of the viewer, then compare this with your list of valid IP's. If it is an invalid IP, simply redirect to an Access Denied page or something.

Code:
ip = Request.ServerVariables("REMOTE_ADDR")
If Not ip = "123.456.789.1" Then
  Response.Redirect("badip.asp")
End If
[Thanks in advance|Hope I helped you]
Exodus300
World-Wide Alliance of Evil and Twisted People
[red]"Experimentation by Example is the best learning tool" - Exodus300[/red]
Code:
if (pop_tarts == 0)
{
   tantrum = 1;
}
[pc3]
 
One note on using Request.ServerVariables. Any user/client that connects from behind a proxy server or gateway is not going to pass you their correct IP address. Instead you are going to get the IP address of the proxy/gateway machine. The reason I warn you of this is if you try to add an IP from behind one of these to your accepted list, it will never be accepted as the actual client machines IP will not make it to your server. If you decide to get around that by using the gateways IP address, than anybody from behind the gateway will have access.
-Tarwn ------------ My Little Dictionary ---------
Extreme Programming - (1)Trying to code before my second cup of coffee. (2) While(1){ Ctrl+C; Ctrl+V; }
FAQ - Web-ese for "Forget Asking Questions, I am to busy" :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top