I wrote a VBscript to automate IIS7 setup to use with ISAPI extension.
It creates absolutely the same XML node in the global config file as if I add the handler
mapping manually via the UI. But if I add the mapping manually, the
server works as it should (loads and calls the extension's dll, (does
not matter the requested file exists or not)), but if I use the script
like below, the server sends the file back to the client (if the file
exist) or returns the 404 if the file does not exist.
const TrgExt = "*.sxt"
const waDll = "myISAPI.dll"
Dim adminManager
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
call AddHandlierMapping( adminManager, "C:\app_folder" )
function AddHandlierMapping( adminManager, path )
On Error Resume Next
Err.Clear
Dim handlersSection, handlersSectionCollection, addElement, addProperties
Set handlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST")
Set handlersSectionCollection = handlersSection.Collection
Set addElement = handlersSectionCollection.CreateNewElement("add")
Set addProperties = addElement.Properties
addProperties.Item("name").Value = "Tree"
addProperties.Item("path").Value = "*" & TrgExt
addProperties.Item("verb").Value = "*"
addProperties.Item("modules").Value = "IsapiModule"
addProperties.Item("scriptProcessor").Value = path & "\" & waDll
addProperties.Item("resourceType").Value = "Unspecified"
addProperties.Item("preCondition").Value = "bitness32"
handlersSectionCollection.AddElement( addElement )
adminManager.CommitChanges()
end function
What's wrong? The answer - the order.
The AddElement() should be called with the second parameter which is the position in the list:
handlersSectionCollection.AddElement( addElement, 0 )
Monday, July 19, 2010
IIS tricks
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment