Writing to IIS6 metabase and Type i = Type.GetTypeFromProgID("IPSecurity"); ???

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top