IIS7 GrantByDefault

Posted by jonot on Stack Overflow See other posts from Stack Overflow or by jonot
Published on 2010-04-09T07:11:28Z Indexed on 2010/04/09 7:13 UTC
Read the original article Hit count: 429

Filed under:
|
|
|

I have an application (written in c#) that allow me to set IIS to allow or deny access to a website from all ip addresses. The application works fine for IIS6 however it does not work with IIS 7 (even with IIS 6 WMI Compatibility installed).

heres the code (basically)

Type typ = this.Entry.Properties[IIsWebDirectoryProperty.IPSecurity][0].GetType();
var securityProp = this.Entry.Properties[IIsWebDirectoryProperty.IPSecurity][0];

typ.InvokeMember("GrantByDefault",
    BindingFlags.DeclaredOnly |
    BindingFlags.Public | BindingFlags.NonPublic |
    BindingFlags.Instance | BindingFlags.SetProperty,
    null, securityProp, new object[] { IPSecurity.GrantByDefault });

this.Entry.CommitChanges();

I have checked the metabase for both IIS6 and IIS7 using the metabase explorer and the only diffecnce I can see is that the "IPSecurity" property does not appear in IIS7 until you also add a an allow or deny IP address, through IIS Manager. Whats really got me stumped is that even when I edit the feature setting to Deny access in the IIS Manager there is no change to the metabase or to the web.config in the site root! So how/where is this property being set and read from? And how can I set and read value of this property programmatically?

© Stack Overflow or respective owner

Related posts about iis7

Related posts about iis6