B
b.parnell
Hi there, I have written a function to set the IPSecurity for a website
in IIS6. However,
when I execute the web page and apprempt to set the IPSecurity property
I get the following error:
Value does not fall within the expected range.
Does anyone have an ideas as to what may be causing this?
Code follows:
Function SetIPSettings(ByVal username, ByVal ServerIndex)
''''''''''''''''''''''''''''''''''''''''
'lets set the directory security so that users cannot access
this server outside the local network
' Remember to enable Integrated Windows authentication and
' disable Anonymous Access, or you will get a Server 500 error.
Dim NewDir As Object
Dim websrvr As Object
Dim MyIPSec As IISOle.IPSecurity
Dim IPList() As Object
Dim MyIPList(15) As Object
Dim ULimit, MyCount, i As Integer
Dim a As Integer
'define ip address range array
MyIPList(0) = "193.60.160.0, 255.255.255.0"
MyIPList(1) = "193.60.161.0, 255.255.255.0"
MyIPList(2) = "193.60.162.0, 255.255.255.0"
MyIPList(3) = "193.60.163.0, 255.255.255.0"
MyIPList(4) = "193.60.164.0, 255.255.255.0"
MyIPList(5) = "193.60.165.0, 255.255.255.0"
MyIPList(6) = "193.60.166.0, 255.255.255.0"
MyIPList(7) = "193.60.167.0, 255.255.255.0"
MyIPList(8) = "193.60.168.0, 255.255.255.0"
MyIPList(9) = "193.60.169.0, 255.255.255.0"
MyIPList(10) = "193.60.170.0, 255.255.255.0"
MyIPList(11) = "193.60.171.0, 255.255.255.0"
MyIPList(12) = "193.60.172.0, 255.255.255.0"
MyIPList(13) = "193.60.173.0, 255.255.255.0"
MyIPList(14) = "193.60.174.0, 255.255.255.0"
MyIPList(15) = "193.60.175.0, 255.255.255.0"
websrvr = GetObject("IIS://" & comp & "/w3svc/" & ServerIndex)
OutputTrace("Setting IP Restrictions for website: " & UserName
& "." & DNSZone)
OutputTrace("Index: " & ServerIndex)
OutputTrace(websrvr.ServerComment)
OutputTrace("")
websrvr = Nothing
NewDir = Nothing
MyIPSec = Nothing
Try
NewDir = GetObject("IIS://" & comp & "/w3svc/" &
ServerIndex & "/ROOT")
Catch ex As Exception
OutputTrace("Error Setting Server Object")
OutputTrace(ex.Message)
End Try
OutputTrace("NewDir")
OutputTrace(NewDir)
Try
MyIPSec = NewDir.IPSecurity
Catch ex As Exception
OutputTrace("Error setting ipsec object")
OutputTrace(ex.Message)
End Try
' Make sure GrantByDefault=FALSE or your changes will not
count.
If (True = MyIPSec.GrantByDefault) Then
OutputTrace("GrantByDefault was not FALSE. Setting to
FALSE.")
MyIPSec.GrantByDefault = False
End If
' Get the Grant list as an array, and add your newly allowed IP
address
IPList = MyIPSec.IPGrant
OutputTrace("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
For a = 0 To UBound(IPList)
OutputTrace(a & " : " & IPList(a))
Next
OutputTrace("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
OutputTrace("Ulimit: " & UBound(IPList))
'check to see what the ulimit is set to, if it is -1 then there
are no current
'entries so we have to start from scratch.
ULimit = UBound(IPList)
If ULimit = -1 Then
ULimit = 0
End If
MyCount = 0
If ULimit > 0 Then ULimit = ULimit + 1
ReDim Preserve IPList(ULimit + UBound(MyIPList))
OutputTrace("..." & (ULimit + UBound(MyIPList)))
OutputTrace("=======================================")
'add the new IP addresses to the existing entries for the
directory.
OutputTrace("IPList: " & UBound(IPList))
For i = ULimit To UBound(IPList)
IPList(i) = MyIPList(MyCount)
OutputTrace(i & " : " & IPList(i))
MyCount = MyCount + 1
Next 'i
OutputTrace("=======================================")
' Set the new lists back in the metabase in two stages, and
then set
' the metabase.
OutputTrace("New Array")
OutputTrace("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
For a = 0 To UBound(IPList)
OutputTrace(a & " : " & IPList(a))
Next
OutputTrace("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
Try
MyIPSec.IPGrant = IPList
Catch ex As Exception
OutputTrace("ERROR")
OutputTrace(ex.Message)
End Try
OutputTrace("Setting Site Security")
Try
NewDir.IPSecurity = MyIPSec
Catch ex As Exception
OutputTrace("Error occured setting site security")
OutputTrace("IP Restrictions have NOT been set")
OutputTrace(ex.Message)
SetIPSettings = -1
End Try
NewDir.setinfo()
NewDir = Nothing
SetIPSettings = 0
End Function
in IIS6. However,
when I execute the web page and apprempt to set the IPSecurity property
I get the following error:
Value does not fall within the expected range.
Does anyone have an ideas as to what may be causing this?
Code follows:
Function SetIPSettings(ByVal username, ByVal ServerIndex)
''''''''''''''''''''''''''''''''''''''''
'lets set the directory security so that users cannot access
this server outside the local network
' Remember to enable Integrated Windows authentication and
' disable Anonymous Access, or you will get a Server 500 error.
Dim NewDir As Object
Dim websrvr As Object
Dim MyIPSec As IISOle.IPSecurity
Dim IPList() As Object
Dim MyIPList(15) As Object
Dim ULimit, MyCount, i As Integer
Dim a As Integer
'define ip address range array
MyIPList(0) = "193.60.160.0, 255.255.255.0"
MyIPList(1) = "193.60.161.0, 255.255.255.0"
MyIPList(2) = "193.60.162.0, 255.255.255.0"
MyIPList(3) = "193.60.163.0, 255.255.255.0"
MyIPList(4) = "193.60.164.0, 255.255.255.0"
MyIPList(5) = "193.60.165.0, 255.255.255.0"
MyIPList(6) = "193.60.166.0, 255.255.255.0"
MyIPList(7) = "193.60.167.0, 255.255.255.0"
MyIPList(8) = "193.60.168.0, 255.255.255.0"
MyIPList(9) = "193.60.169.0, 255.255.255.0"
MyIPList(10) = "193.60.170.0, 255.255.255.0"
MyIPList(11) = "193.60.171.0, 255.255.255.0"
MyIPList(12) = "193.60.172.0, 255.255.255.0"
MyIPList(13) = "193.60.173.0, 255.255.255.0"
MyIPList(14) = "193.60.174.0, 255.255.255.0"
MyIPList(15) = "193.60.175.0, 255.255.255.0"
websrvr = GetObject("IIS://" & comp & "/w3svc/" & ServerIndex)
OutputTrace("Setting IP Restrictions for website: " & UserName
& "." & DNSZone)
OutputTrace("Index: " & ServerIndex)
OutputTrace(websrvr.ServerComment)
OutputTrace("")
websrvr = Nothing
NewDir = Nothing
MyIPSec = Nothing
Try
NewDir = GetObject("IIS://" & comp & "/w3svc/" &
ServerIndex & "/ROOT")
Catch ex As Exception
OutputTrace("Error Setting Server Object")
OutputTrace(ex.Message)
End Try
OutputTrace("NewDir")
OutputTrace(NewDir)
Try
MyIPSec = NewDir.IPSecurity
Catch ex As Exception
OutputTrace("Error setting ipsec object")
OutputTrace(ex.Message)
End Try
' Make sure GrantByDefault=FALSE or your changes will not
count.
If (True = MyIPSec.GrantByDefault) Then
OutputTrace("GrantByDefault was not FALSE. Setting to
FALSE.")
MyIPSec.GrantByDefault = False
End If
' Get the Grant list as an array, and add your newly allowed IP
address
IPList = MyIPSec.IPGrant
OutputTrace("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
For a = 0 To UBound(IPList)
OutputTrace(a & " : " & IPList(a))
Next
OutputTrace("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
OutputTrace("Ulimit: " & UBound(IPList))
'check to see what the ulimit is set to, if it is -1 then there
are no current
'entries so we have to start from scratch.
ULimit = UBound(IPList)
If ULimit = -1 Then
ULimit = 0
End If
MyCount = 0
If ULimit > 0 Then ULimit = ULimit + 1
ReDim Preserve IPList(ULimit + UBound(MyIPList))
OutputTrace("..." & (ULimit + UBound(MyIPList)))
OutputTrace("=======================================")
'add the new IP addresses to the existing entries for the
directory.
OutputTrace("IPList: " & UBound(IPList))
For i = ULimit To UBound(IPList)
IPList(i) = MyIPList(MyCount)
OutputTrace(i & " : " & IPList(i))
MyCount = MyCount + 1
Next 'i
OutputTrace("=======================================")
' Set the new lists back in the metabase in two stages, and
then set
' the metabase.
OutputTrace("New Array")
OutputTrace("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
For a = 0 To UBound(IPList)
OutputTrace(a & " : " & IPList(a))
Next
OutputTrace("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
Try
MyIPSec.IPGrant = IPList
Catch ex As Exception
OutputTrace("ERROR")
OutputTrace(ex.Message)
End Try
OutputTrace("Setting Site Security")
Try
NewDir.IPSecurity = MyIPSec
Catch ex As Exception
OutputTrace("Error occured setting site security")
OutputTrace("IP Restrictions have NOT been set")
OutputTrace(ex.Message)
SetIPSettings = -1
End Try
NewDir.setinfo()
NewDir = Nothing
SetIPSettings = 0
End Function