IIS FastCGI scriptProcessor with spaces in Path

fastcgiiis

I am trying to configure a FastCGI Module – the whole thing works fine if I use a path without spaces, but our application is installed into C:\Program Files and other paths where spaces are common.

The relevant part of the web.config looks like this:

Please not that the Part after the Pipe |is used to configure WFastCGI – a method to run a python WSGI server behind the IIS.

Best Answer

You have to enclose the path to the Python script in double quotes. Double quotes have to be escaped in XML using ".

You do NOT have to enclose the path to the Python executable in double quotes! In fact, this will not work! If your Python installation is in a non-standard path containing spaces, then you don't need to do anything, as spaces will just work for the executable path (it isn't really IIS/FastCGI module that has issues with spaces, but the invocation of Python where the script path is to be passed as a single argument).

As an example, here is what the configuration looks like if Python is installed in a non-standard path containing spaces (just replace it with C:\python27\ if that doesn't apply to you).

In applicationHost.config:

<fastCgi>
  <application
   fullPath="C:\Program Files (x86)\MyApp\Python\python.exe"
   arguments="&quot;C:\Program Files (x86)\MyApp\Python\Lib\site-packages\wfastcgi.py&quot;"
   [...] />
</fastCgi>

In web.config:

<add name="MyHandler"
    path="myapp.py"
    verb="*"
    modules="FastCgiModule"
    scriptProcessor="C:\Program Files (x86)\MyApp\Python\python.exe|&quot;C:\Program Files (x86)\MyApp\Python\Lib\site-packages\wfastcgi.py&quot;"
    resourceType="Unspecified"
    requireAccess="Script" />

EDIT: To set up applicationHost.config programmatically using appcmd.exe, you must escape the double quotes in the argument as \". For example:

set config /section:system.webServer/fastCgi /+"[
  fullPath='C:\Program Files (x86)\MyApp\Python\python.exe',
  arguments='\"C:\Program Files (x86)\MyApp\Python\Lib\site-packages\wfastcgi.py\"',
  [...]