0

I serve an application under a website on IIS but I can't access static folder (where are my CSS files and pictures). I tried few options following tips (IIS7, web.config to allow only static file handler in directory /uploads of website and How to fetch static CSS files with django on IIS?) but neither works.

My structure on IIS is below with static as a virtual directory of the app: IIS structure

My app is online but without CSS and pictures.

What is the solution? Thanks for your help!

Edit on 1st of February:

Handler on static folder

web.config file

Fred
  • 169
  • 1
  • 3
  • 19
  • You can try to remove the Flask handler in virtual directory handler mapping. – Ding Peng Feb 01 '21 at 06:12
  • I have only one handler which is StaticFileModule. I've made an edit on the original post with web.config code snippet + handler on static folder. Thank you for your time for helping. – Fred Feb 01 '21 at 08:19
  • How did you publish the Flask project to IIS? Is it through VS? – Ding Peng Feb 02 '21 at 08:56
  • I put the folder on the server, created a website on IIS manager, then an app with an alias. – Fred Feb 02 '21 at 16:15

1 Answers1

1

I think static folder does not need to use virtual directory.

Here is my demo:

I created a Flask project using the default template in VS and published it to the folder:

enter image description here

web.config is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="Flask" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python\python.exe|C:\Python\lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
        </handlers>
                <security> 
            <requestFiltering allowDoubleEscaping="true"></requestFiltering> 
        </security> 
    </system.webServer>
       <appSettings>
        <!-- Required settings -->
        <add key="WSGI_HANDLER" value="FlaskWebProject1.app" />
        <add key="PYTHONPATH" value="~/" />
    </appSettings>
</configuration>

The directory structure of this project in IIS is as follows:

enter image description here

enter image description here

UDDATE:

enter image description here

It should be noted that when adding static files as virtual directories, they must be added under the main application.

enter image description here

enter image description here

The static folder needs to be at the same level as flask.Because the request for static files by default is requested under the main application:

enter image description here

Ding Peng
  • 3,702
  • 1
  • 5
  • 8
  • It is very clear, thank you. But I have no issue when I serve the app as a website, but not as an application with an alias. Could you try your demo as application under website please? – Fred Feb 03 '21 at 12:40
  • 1
    Woooow, this is huge, thanks a lot for your help!!! It works and it is very clear! But how can I store multiple apps under a same website with different static folders? Really and siuncerely many thanks, it was a nightmare! – Fred Feb 04 '21 at 20:55