Programmatically add an ISAPI extension dll in IIS 7 using ADSI?

Posted by fretje on Server Fault See other posts from Server Fault or by fretje
Published on 2010-04-21T09:15:06Z Indexed on 2010/04/21 9:23 UTC
Read the original article Hit count: 1183

Filed under:
|
|

I apologize beforehand, this is a cross post of this SO question. I thought I'd ask it there first, but apparently it doesn't harvest any answers there. I hope it will get more attention here. When I have an answer somewhere, I'll delete the other one.


I'm trying to programmatically add an ISAPI extension dll in IIS using ADSI. This has been working for ages on previous versions of IIS, but it seems to fail on IIS 7.

I am using similar code like shown in this question:

var web = GetObject("IIS://localhost/W3SVC/1/ROOT/specificVirtualDirectory");
var maps = web.ScriptMaps.toArray();
map[maps.length] = ".aaa,c:\\path\\to\\isapi\\extension.dll,1,GET,POST";
web.ScriptMaps = maps.asDictionary();
web.SetInfo();

After executing that code, I do see an "AboMapperCustom-12345678" entry for that specific dll in the "Handler mappings" of the specific virtual directory in which I added the script map. But when I try to use that extension in a browser, I always get

HTTP Error 404.2 Not Found
The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server.

Even after adding an entry to allow that specific dll in the "ISAPI and CGI restrictions", I keep getting that error.

To make it actually work, I first have to undo these steps (encountering the same issue like the OP of the question mentioned above: after deleting the script map entry from the IIS manager GUI, I also have to programmatically delete it using ADSI before it's actually gone from the metabase).

And then manually add an entry like this:

  • inetmgr -> webserver -> website -> virtual directory -> handler mappings -> add script map...
  • path = *.dll, executable = <path to dll>, name = <doesn't matter, but it's mandatory>
  • click "yes" on the question "do you want to allow this ISAPI extension?"

When I compare the 2 entries, they are exactly the same, except for the "Entry Type" which seems to be "Inherited" for the programmatically added one and "Local" for the one added manually.

The strange thing is, even though it says "Inherited", I don't see it anywhere in IIS on a higher level. Where is it inheriting from?

In my code, I do add the script map to the specific virtual directory so it should be "Local" as well. Maybe there is the problem, but I don't know how to add a "Local" Script Map using ADSI.

I really would like to keep using the ADSI method, as otherwise I will have to use different methods in our setup when working with IIS 7 or previous versions, and I would like to avoid that.

To recap: How can I programmatically add a script map entry and its companion CGI and ISAPI restrictions entry to IIS 7 using ADSI?

Anybody who can shed some light on this? Any help appreciated.

© Server Fault or respective owner

Related posts about adsi

Related posts about iis7