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.ServerV ariables("HTTP_ X_FORWARDED_FOR ")
if sIPAddress = "" then
sIPAddress = Request.ServerV ariables("REMOT E_ADDR")
End If
%>
<script language="VB" runat=server>
function BannedIP(sIPAdd ress)
Dim sBanned
sBanned =
Array("69.202.1 23.157","216.23 9.39.5","216.23 9.37.5","216.23 9.37.104","2
16.155.200.231" ,"216.155.200.2 32","216.155.20 0.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(sIPAdd ress) 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","value 3")
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
############### ############### #######
Jul 21 '05
29 4058
Friday,
It seems that we all had sht in our eyes.
Dim sBanned() As String = {"69.202.123.15 7", "216.239.39 .5",
"216.239.37 .5", "216.239.37.104 ", "216.155.200.23 1", "216.155.200.23 2",
"216.155.200.23 3", "216.155.200.23 4"}
( = {
) = }
:-)
I hope this helps,
Cor
Friday <fr****@nowhere .org> wrote: OK! Now I'm getting somewhere. When I replace the () in the array with containers {}, the compiler gets happy. :-) (WTF?! Oh well.)
<snip>
At this stage, I would *seriously* give up on just experimenting within
ASPX. It's really not a good way of learning any language unless you
already have a reasonably solid foundation and are just checking one
particular aspect - and even then I'd check the spec afterwards.
I suggest you start learning VB.NET (or C#) with small console apps,
and when you're happy with the language itself without the ASP.NET
adornments, *then* move on to web apps.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
In article <MP************ ************@ms news.microsoft. com>, Jon Skeet
[C# MVP] <sk***@pobox.co m> wrote: Friday <fr****@nowhere .org> wrote: OK! Now I'm getting somewhere. When I replace the () in the array with containers {}, the compiler gets happy. :-) (WTF?! Oh well.)
<snip>
At this stage, I would *seriously* give up on just experimenting within ASPX. It's really not a good way of learning any language unless you already have a reasonably solid foundation and are just checking one particular aspect - and even then I'd check the spec afterwards.
I suggest you start learning VB.NET (or C#) with small console apps, and when you're happy with the language itself without the ASP.NET adornments, *then* move on to web apps.
Thanks Jon,
Iunderstand, and agree with your reasoning 100%. One day, time
permitting, I would like to learn this intriguing and powerful language
more thoroughly.
What I'm striving to do at this point, is to convert a series of PHP
scripts I make my living with to work for a client who recently
migrated to IIS. The rest Ive researched (along with the basics), but
this one small part has become a sticking point.
Thanks to the help of all the knowledgeable and helpful folks here,
however, I'm 99% there.
Thanks Again and Have a GREAT Day (Week, Year, and Beyond),
:-)
Sincerely,
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
############### ############### #######
In article <On************ **@TK2MSFTNGP14 .phx.gbl>, Cor Ligthert
<no************ @planet.nl> wrote: Friday,
It seems that we all had sht in our eyes. Dim sBanned() As String = {"69.202.123.15 7", "216.239.39 .5", "216.239.37 .5", "216.239.37.104 ", "216.155.200.23 1", "216.155.200.23 2", "216.155.200.23 3", "216.155.200.23 4"}
( = { ) = }
:-)
I hope this helps,
Cor
THat was indeed the problem, Cor.
The only way I caught it was that I noticed than an earlier poster had
used the '{' indstead of the '(' So I tried it, not really expecting it
to make a diofference, but whether working on a car that stalls, or
programming, I always look to the seemingly insiognificant ("Stupid" if
you will) little things first. Or at least I try to make a practice of
that.
:-)
Odd thing that it would make the difference.
But MS never was much for adhering to time-honored standards, were they?
;-)
Thanks Again for Taking the Time to Help,
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
############### ############### #######
In article <MP************ ************@ms news.microsoft. com>, Jon Skeet
[C# MVP] <sk***@pobox.co m> wrote: Friday <fr****@nowhere .org> wrote: OK! Now I'm getting somewhere. When I replace the () in the array with containers {}, the compiler gets happy. :-) (WTF?! Oh well.)
<snip>
At this stage, I would *seriously* give up on just experimenting within ASPX. It's really not a good way of learning any language unless you already have a reasonably solid foundation and are just checking one particular aspect - and even then I'd check the spec afterwards.
I suggest you start learning VB.NET (or C#) with small console apps, and when you're happy with the language itself without the ASP.NET adornments, *then* move on to web apps.
Which would you recomnmend?
VB or C#
Or does it depend upon which language the site is built around?
Thx Agn
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
############### ############### #######
In article <MP************ ***********@msn ews.microsoft.c om>, Jon Skeet
[C# MVP] <sk***@pobox.co m> wrote: Cor Ligthert <no************ @planet.nl> wrote: I never use the notation from you. I use for Net1.1
Dim sBanned() As String = ("69.202.123.15 7","216.239.39. 5","216.239.37. 5","216.239.37. 104","2 16.155.200.231" ,"216.155.200.2 32","216.155.20 0.233","216.155 .200.234") For i as integer = 0 to sBanned.length - 1 If sBanned(i) = selCriteria Then BannedIP = True Else BannedIP = False End Function
Just to find an element within an array, I'd suggest using Array.IndexOf. (In this case, Array.IndexOf(s Banned, selCriteria).) If the return value is -1, the element isn't found. Otherwise, it is.
Excelent Jon!
Fewer lines of code is GOOD.
This works well for my intended application:
############### ###########
function BannedIP(sIPAdd ress As String) As Boolean
Dim selCriteria as String
selCriteria = sIPAddress
Dim sBanned() As String =
{"68.142.230.18 1","66.228.164. 108","202.165.9 8.144"}
If Array.IndexOf(s Banned, selCriteria) > -1 Then
IsMember = True
End If
End Function
############### ############### ####
Very tight.
Seems I don't even need the "Else = False"
Or would it be considered bad protocall to leave that out?
Many Thx
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
############### ############### #######
Friday <fr****@nowhere .org> wrote: I suggest you start learning VB.NET (or C#) with small console apps, and when you're happy with the language itself without the ASP.NET adornments, *then* move on to web apps.
Which would you recomnmend? VB or C# Or does it depend upon which language the site is built around?
Personally I'd recommend C# as having a cleaner syntax and less baggage
from the past. Certainly if you're not familiar with VB to start with,
C# is the more natural choice for most people.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Friday <fr****@nowhere .org> wrote: This works well for my intended application: ############### ########### function BannedIP(sIPAdd ress As String) As Boolean
Dim selCriteria as String selCriteria = sIPAddress
Dim sBanned() As String = {"68.142.230.18 1","66.228.164. 108","202.165.9 8.144"}
If Array.IndexOf(s Banned, selCriteria) > -1 Then IsMember = True End If
End Function ############### ############### #### Very tight.
Seems I don't even need the "Else = False" Or would it be considered bad protocall to leave that out?
I'm afraid I don't know what VB does in terms of unspecified function
return values.
However, you could just change it to:
IsMember = (Array.IndexOf( sBanned, selCriteria) > -1)
Or at least, you could in C# and I assume you can in VB.NET...
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" However, you could just change it to:
IsMember = (Array.IndexOf( sBanned, selCriteria) > -1)
Or at least, you could in C# and I assume you can in VB.NET...
Function BannedIP(ByVal sIPAddress As String) As Boolean
Dim sBanned() As String = {"68.142.230.18 1", _
"66.228.164.108 ", "202.165.98.144 "}
Return (Array.IndexOf( sBanned, sIPAddress) > -1)
End Function
I don't know if it goes still shorter.
Cor
In article <MP************ ************@ms news.microsoft. com>, Jon Skeet
[C# MVP] <sk***@pobox.co m> wrote: Friday <fr****@nowhere .org> wrote: This works well for my intended application: ############### ########### function BannedIP(sIPAdd ress As String) As Boolean
Dim selCriteria as String selCriteria = sIPAddress
Dim sBanned() As String = {"68.142.230.18 1","66.228.164. 108","202.165.9 8.144"}
If Array.IndexOf(s Banned, selCriteria) > -1 Then IsMember = True End If
End Function ############### ############### #### Very tight.
Seems I don't even need the "Else = False" Or would it be considered bad protocall to leave that out?
I'm afraid I don't know what VB does in terms of unspecified function return values.
However, you could just change it to:
IsMember = (Array.IndexOf( sBanned, selCriteria) > -1)
Or at least, you could in C# and I assume you can in VB.NET...
Hmmm.... nice.
--
############### ############### #######
"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
############### ############### ####### This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JNY |
last post by:
Hello,
Is it possible to declare an array with variable indeces?
i.e.
int x = 4;
int myArray;
for (j = 0;j < 5;j++)
{
|
by: Friday |
last post by:
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.
|
by: Peter Duniho |
last post by:
On Thu, 14 Aug 2008 18:56:00 -0700, Phill
<Phill@discussions.microsoft.comwrote:
For future reference, if you are asking for help with an error (compile or
execution), you really should post the complete text of the error and be
specific about when and where it happens.
That said, in your code it's clear what's wrong:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |