2

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.

Christian Sauer
  • 125
  • 1
  • 6

2 Answers2

1

try the short 8.3 filename. Using a command prompt, navigate to location where your executable is and use the following command:

dir /x

That will give you the long and short path name. The short path name should have no spaces. Check if that works out for you.

milope
  • 441
  • 2
  • 5
  • This works, but if IIS has to be configured programmatically, that means it is also necessary to compute the 8.3 path programmatically. Does the 8.3 path always stay the same, or may it change if new long filenames are created? Do 8.3 paths work on all Windows systems, even in the future? Is there no way to escape spaces? At least for wfastcgi, double-quotes (encoded as " in IIS config XML files) do not work. – Florian Winter Aug 04 '17 at 13:06
  • I was thinking about that myself, but I haven't tried it. You can try   and find out if that works. If so, it will probably be a cleaner solution than the 8.3 path. – milope Aug 04 '17 at 13:08
  • Nope, spaces don't need escaping in XML. Plan B is to compute the 8.3 path programmatically using dir /x (yikes!). If I come across a plan A, I will post it here. Thanks anyway, you saved me some hours of debugging in the dark. – Florian Winter Aug 04 '17 at 13:12
  • Windows 8.3 filenames are believed to have security issues, so they may be disabled by Windows registry on some servers. Relying on 8.3 filenames can therefore clash with security policies in some environments. https://cwe.mitre.org/data/definitions/58.html – Florian Winter Aug 07 '17 at 08:27
  • I get that, but at the same time I've run into users whom have over hardened their GPO (which are also registry keys) to the point IIS no longer runs properly. Anyway another thing I haven't tried are environment variables. Not sure if that particular property expands it. – milope Aug 07 '17 at 11:13
  • Another workaround is a wrapper Python script in a path without spaces that loads `wfastcgi.py` using something like https://stackoverflow.com/a/67692/2279059 ... There are a lot of simple workarounds that are acceptable if you are hosting the app on your own server and setting up everything manually. The opposite scenario is on-premises software that is installed automatically, which requires a more clean approach which makes as few assumptions about the system (and the customer's security policies) as possible. – Florian Winter Aug 07 '17 at 11:34
1

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\"',
  [...]
Florian Winter
  • 214
  • 1
  • 2
  • 10