This is just a note (mainly to self) on a couple of tweaks you have to make to IIS 7 in order to run Mapserver on IIS 7. Last couple of days I was banging my head against a wall trying to figure out why I was getting this error on a web site I was developing:
Could not load file or assembly ‘mapscript_csharp’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
I was certain all required dlls were there and the application was running fine from within Visual Studio 2010. It was only when I was publishing it that the error was occurring. And it was also working fine on an IIS 6 server.
As it turned out it was an IIS 7 setting (as it invariably is). Apparently IIS does not allow by default 32-bit applications in the Default Application pool. So all I had to do was to go to IIS Manager, and then select DefaultAppPool->Advanced Settings:
After changing the [Enable32-Bit] Applications to True all was well and I was a happy bunny again.
However, while I was investigating the above problem, I tried to run mapserver in cgi mode just to make sure all my dlls were correct. I was immediately hit by another couple of issues (admittedly due to my very thin knowledge on IIS 7).
The first one was how to enable CGI apps. This is pretty straight forward:
On IIS Manager select the machine node (the name of your machine) on the left and then click on the ISAPI and CGI restrictions icon
On the ISAPI and CGI restrictions page, select the [Add] action and in the displayed dialog enter the path of your mapserv.exe executable along with a name:
That would have sorted you would think- right? Well, not quite. You see, my mapserv.exe file was under the bin folder of my website (where all the other mapserver dlls were located) and when I tried to run the mapserv.exe I got this error:
HTTP Error 404.8 – Not Found
The request filtering module is configured to deny a path in the URL that contains a hiddenSegment section.
IIS again. To ‘fix’ this (although not sure you want to do this on a permanent basis), is to click on the [Request Filtering] icon for your Web application:
You should see a list containing all the hidden folders and files (aka segments). Select bin and click on [Remove] on the Actions list.
But that’s not all. The last thing you need to do, is to add execute permission on the Web app. To do this, select the Handler Mappings icon, select Feature Permissions for in the Actions list and click on the Execute box.
You should now be able to run mapserv as CGI and get this soothing message:
All done. Hope this helps someone!.