D
DAve
I want to be able to limit access to a folder in IIS by IP address. I
am trying to add IP addresses from a WebMethod to the IPGrant property.
Here's my code:
DirectoryEntry defaultRoot = new
DirectoryEntry("IIS://SERVERNAME/w3svc/1/root/examplefolder",username,password,
AuthenticationTypes.Secure);
defaultRoot.RefreshCache();
object oIPSecurity = defaultRoot.Invoke("Get", new
string[]{"IPSecurity"});
Type t = oIPSecurity.GetType();
//Get the list of granted IPs
Array IPs = (Array)t.InvokeMember("IPGrant", BindingFlags.GetProperty,
null, oIPSecurity, null);
//create a new Array of IPs
object[] newIPs = new object[IPs.Length+1];
//copy the existing IPs to the new Array
IPs.CopyTo(newIPs,0);
//add a new value
newIPs.SetValue("192.168.0.21",IPs.Length);
//Set the new IPlist
t.InvokeMember("IPGrant", BindingFlags.SetProperty, null, oIPSecurity,
new object[]{newIPs});
defaultRoot.Invoke("Put", new object[]{"IPSecurity", oIPSecurity});
defaultRoot.CommitChanges();
When executed, I get this error:
System.UnauthorizedAccessException: Access is denied. at
System.DirectoryServices.Interop.IAds.SetInfo() at
System.DirectoryServices.DirectoryEntry.CommitChanges()
ideas to accomplish this?
Thanks,
David
am trying to add IP addresses from a WebMethod to the IPGrant property.
Here's my code:
DirectoryEntry defaultRoot = new
DirectoryEntry("IIS://SERVERNAME/w3svc/1/root/examplefolder",username,password,
AuthenticationTypes.Secure);
defaultRoot.RefreshCache();
object oIPSecurity = defaultRoot.Invoke("Get", new
string[]{"IPSecurity"});
Type t = oIPSecurity.GetType();
//Get the list of granted IPs
Array IPs = (Array)t.InvokeMember("IPGrant", BindingFlags.GetProperty,
null, oIPSecurity, null);
//create a new Array of IPs
object[] newIPs = new object[IPs.Length+1];
//copy the existing IPs to the new Array
IPs.CopyTo(newIPs,0);
//add a new value
newIPs.SetValue("192.168.0.21",IPs.Length);
//Set the new IPlist
t.InvokeMember("IPGrant", BindingFlags.SetProperty, null, oIPSecurity,
new object[]{newIPs});
defaultRoot.Invoke("Put", new object[]{"IPSecurity", oIPSecurity});
defaultRoot.CommitChanges();
When executed, I get this error:
System.UnauthorizedAccessException: Access is denied. at
System.DirectoryServices.Interop.IAds.SetInfo() at
System.DirectoryServices.DirectoryEntry.CommitChanges()
problem is going to be a security threat. Any thoughts or alternativeFrom the research I've done, I'm concerned that the solution to this
ideas to accomplish this?
Thanks,
David