A
alex
I am trying to implement "Ban user IP" functionality in my webapp by
writing directly to IIS6 metabase. There is IPSecurity section that
allows deny access for specific ip addresses. Here Ive found some
samples but cant get it to work. Any help is greatly appreciated!
The problem occurs on this line: Type i =
Type.GetTypeFromProgID("IPSecurity");
"IPSecurity" progID is not correct. How do I get right one?
using System;
using System.DirectoryServices;
using System.Reflection;
DirectoryEntry defaultRoot = new DirectoryEntry("IIS://" + serverName
+ "/w3svc/1/root", serverName + "\\administrator", password,
AuthenticationTypes.Secure);
// Put the IPSecurity value into a collection.
PropertyValueCollection ipSecValCollection =
defaultRoot.Properties["IPSecurity"];
Type i = Type.GetTypeFromProgID("IPSecurity");
// System.Activator can create types of objects locally or remotely.
object newObj = Activator.CreateInstance(i);
i.InvokeMember("IPDeny",BindingFlags.Default |
BindingFlags.SetProperty, null,newObj, new object[] {"123.45.67.89"} )
;
// Put the new member into the collection and commit the
changes.
ipSecValCollection.Insert(0,newObj);
defaultRoot.CommitChanges();
defaultRoot.RefreshCache();
writing directly to IIS6 metabase. There is IPSecurity section that
allows deny access for specific ip addresses. Here Ive found some
samples but cant get it to work. Any help is greatly appreciated!
The problem occurs on this line: Type i =
Type.GetTypeFromProgID("IPSecurity");
"IPSecurity" progID is not correct. How do I get right one?
using System;
using System.DirectoryServices;
using System.Reflection;
DirectoryEntry defaultRoot = new DirectoryEntry("IIS://" + serverName
+ "/w3svc/1/root", serverName + "\\administrator", password,
AuthenticationTypes.Secure);
// Put the IPSecurity value into a collection.
PropertyValueCollection ipSecValCollection =
defaultRoot.Properties["IPSecurity"];
Type i = Type.GetTypeFromProgID("IPSecurity");
// System.Activator can create types of objects locally or remotely.
object newObj = Activator.CreateInstance(i);
i.InvokeMember("IPDeny",BindingFlags.Default |
BindingFlags.SetProperty, null,newObj, new object[] {"123.45.67.89"} )
;
// Put the new member into the collection and commit the
changes.
ipSecValCollection.Insert(0,newObj);
defaultRoot.CommitChanges();
defaultRoot.RefreshCache();