F
Friday
Sorry if this is the wrong group. I tried to find the one I thought
would be most relevant.
I'm an old PHP guy, who knows little about asp and NOTHING about
asp.net, but need to learn at least enough to convert a favorite PHP
script to work on an ASP.NET site.
I'm experimenting with simple example scripts that will help me learn
how to implement each "piece" of the puzzle.
Doing well so far... one piece of the puzzle at a time.
I need to create a simple funtion that will check the IP Address of a
visitor against an "array variable" of banned IPs.
In asp, it saeems simple enough. Here's the include that contains the
function to be called (in .asp):
##############################
<%
Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>
<script language="VB" runat=server>
function BannedIP(sIPAddress)
Dim sBanned
sBanned =
Array("69.202.123.157","216.239.39.5","216.239.37.5","216.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233","216.155.200.234")
Dim i
For i = 0 to UBound( [sBanned] )
If selCriteria(i,1) = cstr(sBanned) Then
BannedIP = TRUE
Else
BannedIP = false
End Function
</script>
################################
The function is called from an existing .aspx page thus:
################################
if BannedIP(sIPAddress) then
' show it the "SORRY" page
Server.Execute("sorry.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, go ahead and display this page below
End If
################################
ASP.NET doesn't like this at all!
It tells me: "'Array' is a type and cannot be used as an expression."
:-(
What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")
I would simply use the function as is, written in asp, but the pages
are VERY .aspx and choke on it.
ALSO: My next piece of the puzzle will be to tackle this one, using the
same test script:
If I want e to ban a violator with a dynamic IP, how do I deal with
entire C-blocks (e.g.: BannedIP is TRUE if sIPAdress contains
123.45.6.*)
Many TIA
Friday
--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################
would be most relevant.
I'm an old PHP guy, who knows little about asp and NOTHING about
asp.net, but need to learn at least enough to convert a favorite PHP
script to work on an ASP.NET site.
I'm experimenting with simple example scripts that will help me learn
how to implement each "piece" of the puzzle.
Doing well so far... one piece of the puzzle at a time.
I need to create a simple funtion that will check the IP Address of a
visitor against an "array variable" of banned IPs.
In asp, it saeems simple enough. Here's the include that contains the
function to be called (in .asp):
##############################
<%
Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if sIPAddress = "" then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>
<script language="VB" runat=server>
function BannedIP(sIPAddress)
Dim sBanned
sBanned =
Array("69.202.123.157","216.239.39.5","216.239.37.5","216.239.37.104","2
16.155.200.231","216.155.200.232","216.155.200.233","216.155.200.234")
Dim i
For i = 0 to UBound( [sBanned] )
If selCriteria(i,1) = cstr(sBanned) Then
BannedIP = TRUE
Else
BannedIP = false
End Function
</script>
################################
The function is called from an existing .aspx page thus:
################################
if BannedIP(sIPAddress) then
' show it the "SORRY" page
Server.Execute("sorry.aspx")
' Then STOP! (same as PHP's "exit;" statement ???)
Response.End
' otherwise it's cool, go ahead and display this page below
End If
################################
ASP.NET doesn't like this at all!
It tells me: "'Array' is a type and cannot be used as an expression."
:-(
What is the proper syntax in ASP.NET for:
variable = Array("value1","value2","value3")
I would simply use the function as is, written in asp, but the pages
are VERY .aspx and choke on it.
ALSO: My next piece of the puzzle will be to tackle this one, using the
same test script:
If I want e to ban a violator with a dynamic IP, how do I deal with
entire C-blocks (e.g.: BannedIP is TRUE if sIPAdress contains
123.45.6.*)
Many TIA
Friday
--
#####################################
"The people cannot be all, & always well informed. The part which is wrong will
be discontented in proportion to the importance of the facts they misconceive.
If they remain quiet under such misconceptions it is a lethargy, the forerunner
of death to the public liberty. What country before ever existed a century & a
half without a rebellion? & what country can preserve it's liberties if their
rulers are not warned from time to time that their people preserve the spirit
of resistance? Let them take arms... The tree of liberty must be refreshed from
time to time with the blood of patriots & tyrants"
-- Thomas Jefferson
#####################################