« Previous Next »

Thread: Using ADSI object IIsIPSecurity

Last post 11-18-2008 6:34 PM by masuda0916. 8 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (9 items)

Sort Posts:

  • 11-17-2008, 12:37 AM

    Using ADSI object IIsIPSecurity

    Hi,

    I am trying to block access to certain IP address to my website.

    Following is my server-side code in vb.net

     

    Dim SecObj = GetObject("IIS://localhost/W3SVC/1/Root")
    Dim MyIPSec = SecObj.IPSecurity
    MyIPSec.GrantByDefault = True
    Dim IPList = MyIPSec.IPDeny
    ReDim IPList(UBound(IPList) + 1)
    IPList(UBound(IPList)) = "111.11.11.11"
    MyIPSec.IPDeny = IPList
    SecObj.IPSecurity = MyIPSec
    SecObj.Setinfo()

     

    I am getting error at SecObj.IPSecurity = MyIPSec. The error is "Value doesn't fall within the expected range."

     

    Can someone enlighten me on what is wrong?

    Thank you.

  • 11-17-2008, 6:37 AM In reply to

    Re: Using ADSI object IIsIPSecurity

    I think you need to include the subnet mask...
    IPList (Ubound(IPList)) = "111.11.11.11,255.255.255.0"

    Cheers,
    Bernard Cheah
  • 11-17-2008, 7:28 PM In reply to

    Re: Using ADSI object IIsIPSecurity

    Hi qbernard,

    Thank you very much for your reply and advices.

    I tried to add the subnet mask. However, it still gives me the same error.

    Dim SecObj = GetObject("IIS://localhost/W3SVC/1/Root")
    Dim MyIPSec = SecObj.IPSecurity
    MyIPSec.GrantByDefault = True
    Dim IPList = MyIPSec.IPDeny
    ReDim IPList(UBound(IPList) + 1)
    IPList(UBound(IPList)) = "111.11.11.11,255.255.255.0"
    MyIPSec.IPDeny = IPList
    SecObj.IPSecurity = MyIPSec
    SecObj.Setinfo()

     

    Do I need to import any components? During debugging, I checked the type of MyIPSec, and it was of type System.__ComObject.

    Any help is much appreciated.

     

  • 11-17-2008, 8:53 PM In reply to

    Re: Using ADSI object IIsIPSecurity

    Try this.  I used it to successfully add a lot of exclusions.

    http://forums.iis.net/p/1148477/1865759.aspx

    Steve Schofield
    Windows Server MVP - IIS
    http://weblogs.asp.net/steveschofield


    http://www.IISLogs.com
    Log archival solution
    Install, Configure, Forget
  • 11-17-2008, 9:29 PM In reply to

    Re: Using ADSI object IIsIPSecurity

    Hi Steve,

    Thank you for your suggestion.

    I was referring to the last post of the link that you provided.

    I tried downloading some of the things off http://www.codeplex.com/SLK but I couldn't find IISOLE.dll

    I also tried to google for IISOLE.dll too, but to no avail.

    However, based on the code at the link you proivided, it seems like that should work if IISOLE.dll is available.

  • 11-17-2008, 9:54 PM In reply to

    Re: Using ADSI object IIsIPSecurity

    Hi,

    I managed to set reference to the following after some search,

    - Interop.ActiveDS.dll

    - Interop.IISExt.dll

    - Interop.IISOle.dll

    I could now see properties such as IPGrant and so on under hints while programming, unlike before adding these references.

    However, I still get the same error.

    I could not find the "DirectoryEntry" type.

    Dim SecObj As IISOle.IISBaseObject = GetObject("IIS://localhost/W3SVC/1/Root")
    Dim MyIPSec As IISOle.IISIPSecurity = SecObj.IPSecurity()
    MyIPSec.GrantByDefault = True
    Dim IPList = MyIPSec.IPDeny
    ReDim IPList(UBound(IPList) + 1)
    IPList(UBound(IPList)) = "111.11.11.11,255.255.255.0"
    MyIPSec.IPDeny = IPList
    SecObj.IPSecurity = MyIPSec
    SecObj.Setinfo()

     

    At MyIPSec.IPDeny = IPList, under debugging mode, I can see that the IPDeny array was attached to MyIPSec successfully. But still it got stuck when setting the IPSecurity back to MyIPSec.

    I'm not sure how to workabout to get rid of the latebinding error....

  • 11-17-2008, 9:54 PM In reply to

    Re: Using ADSI object IIsIPSecurity

    After doing some search, I made a reference to System.DirectoryServices and finally got the DirectryEntry namespace.

    With reference to Steve's code and other codes that I found on the internet,

    Dim objValue As New DirectoryEntry("IIS://localhost/W3SVC/1/Root")
    Dim MyIPSec As IISIPSecurity = CType(objValue.Properties("IPSecurity").Value, IISIPSecurity)

    MyIPSec.GrantByDefault = True

    MyIPSec.IPDeny = New Object() {"111.11.11.11"}
    objValue.Properties("IPSecurity").Value = MyIPSec

    objValue.CommitChanges()

     

    There is no more late binding issues.

     

    However, when I moved it to the server to test out, the line CommitChanges caused an AccessDenied exception.

    I am now trying to figure out how to overcome this. Meanwhile I appreciate any suggestions.

    Thank you.

  • 11-18-2008, 5:43 PM In reply to

    Re: Using ADSI object IIsIPSecurity

    Make sure you make a reference to System.DirectoryServices namespace.

    Steve Schofield
    Windows Server MVP - IIS
    http://weblogs.asp.net/steveschofield


    http://www.IISLogs.com
    Log archival solution
    Install, Configure, Forget
  • 11-18-2008, 6:34 PM In reply to

    Re: Using ADSI object IIsIPSecurity

    Hi,

    I did just that and it worked fine.

    Thank you.

Page 1 of 1 (9 items)
Microsoft Communities