Re: Restrict page by IP

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



There's also an extraneous "Else"...

This should cover it, if placed in the Page_Load event :

Dim RemoteAddr as String = Request.ServerVariables("REMOTE_ADDR")
If instr(RemoteAddr, "192.168.0") Then
Response.Redirect ("/Login/entry_denied.asp")
End If

Mark's code is simpler, though.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"David Wier" <davidwier@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:u6R8kmSqHHA.3740@xxxxxxxxxxxxxxxxxxxxxxx
Just put this logic at the very first of the Page_Load routine, in your ASPX page
change Dim RemoteAddr to:
Dim RemoteAddr as String
remove the <% %> tags and you're good to go

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com



"Billy Bob" <not@xxxxxxxxxxxxx> wrote in message news:e5W6$gSqHHA.3228@xxxxxxxxxxxxxxxxxxxxxxx
Working in ASP/VBSCRIPT, I have a snippet that denies access to a page if the user's IP does not
belong to the local network:

<%
Dim RemoteAddr
RemoteAddr = Request.ServerVariables("REMOTE_ADDR")
If instr(RemoteAddr, "192.168.0") Then
Else Response.Redirect ("/Login/entry_denied.asp")
End If
%>

I need to apply this to a ASPX page. Can you help me with the syntax?




.



Relevant Pages

  • Re: Restrict by IP
    ... the user's IP does not belong to the local network: ... I need to apply this to a ASPX page. ... better response. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Restrict page by IP
    ... Just put this logic at the very first of the Page_Load routine, in your ASPX ... change Dim RemoteAddr to: ... Dim RemoteAddr as String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Restrict page by IP
    ... Only Content controls are allowed directly in a content page that contains Content controls. ... for the line Dim RemoteAddr as String ... I need to apply this to a ASPX page. ...
    (microsoft.public.dotnet.framework.aspnet)