2

I have a Delphi ISAPI DLL(32 bit) built with Delphi XE SPI, and hosted on a server running WinServer 2008 RS2 and IIS 7.5.

See MSDN:

Initialization Using GetExtensionVersion:

Initialization is handled by the entry-point function GetExtensionVersion. This function's role is to perform all initialization, including the creation of worker threads, synchronization objects, and database connections, and to establish the version of ISAPI that was used to build the DLL.

In my ISAPI DLL I am using GetExtensionVersion to perform initializations as per the above MSDN reference. GetExtensionVersion is great for initialization of resources that need to persist for the lifetime of the web application, not initialized on a per client request basis, because it's called only once by IIS, when the first request is mapped to your ISAPI DLL. If interested, see How can I make ADO database connections in TISAPIApplication before processing incoming requests? for more details.

One of my initialization functions takes the URL of the website where that DLL is hosted, but I cannot seem to find any Delphi function or property that exposes the website's URL within the context of GetExtensionVersion, which runs before the application begins handling the actual client request - that happens in HttpExtensionProc (which Delphi's TWebApplication hooks into using TWebActionItem).

Since my ISAPI DLL is hosted in a website, and GetExtensionVersion is only called by IIS when a client request is posted to that website, I believe the website's URL should be available somewhere - perhaps through an IIS API call.

How can I grab the URL of my website from within GetExtensionVersion?

Community
  • 1
  • 1
Vector
  • 10,879
  • 12
  • 61
  • 101

1 Answers1

1

You need an extension control block to obtain a URL. It is passed to HttpExtensionProc, but not to GetExtensionVersion. It is possible that IIS doesn't even have the DLL mapped to any website yet when it is calling GetExtensionVersion. Also IIS may be using the same DLL for several websites, and still call GetExtensionVersion once.

Specific to your question I see two options: you could access the IIS Admin API (perhaps with this) to find out which website(s) your DLL is used for, but this probably would be the only thing you need the IIS Admin API for, and require too much access rights which you don't want to run your application under, security-wise.

Another option (one I use myself in xxm) is to call GetModuleFileName on the HInstance global that is available in the DLL, and read configuration files in the directory the DLL is in. (Silently assuming the directory with the DLL itself is not accessible with a URL over IIS...)

Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67
  • _It is possible that IIS doesn't even have the DLL mapped to any website yet when it is calling GetExtensionVersion_ : How so? It's not called until a client request is made to your URL. _Also IIS may be using the same DLL for several websites_ - that depends on how I configure IIS, AFAIK, and I'm not doing that. – Vector Feb 05 '15 at 19:37
  • I put a text file containing the website URL in the directory together with the DLL, used `GetModuleFileName` in `GetExtensionVersion` and chopped up the name a bit to get the text file name and read in the URL I need. A bit roundabout but it appears to be painless and bulletproof. The IIS Admin API is definitely **not** something I want to mess with at the moment. – Vector Feb 05 '15 at 23:30