Writing directly to IIS6 metabase

User avatar
alkapin
Ник удалён за неоплаченную рекламу
Posts: 391
Joined: 15 May 2002 09:16
Location: было оттуда, теперь отсюда

Writing directly to IIS6 metabase

Post by alkapin »

I am trying to implement "Ban user IP" functionality in my webapp (C#, asp.net) 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 the 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();

Return to “Вопросы и новости IT”