Kévin Hamon
Kévin Hamon

Reputation: 1

Url decoding problem on deployment with IIS and FastCGI on windows server

I realized an app front Angular, back-end Django, deployed on Windows server using IIS and FastCGI. This app serves media files on a certain URL. It works fine locally on dev server. I can access all my files correctly on path "medias/myfilepath".

The problem is in production on IIS. Special characters are encoded in a different way. I think it is FastCGI that does it. I cannot find the encoding rules, and my Django app is not able to decode properly so my requests end up with a 404 error.

Here are some examples of the difference of encoding between local server and production server :

I can't find any documentation on the subject, I don't have access to configurations on CGI side. I could update decoding on Django side to fit it, but I can't find which one applies ...

Someone would have some ideas on that subject ?

Upvotes: 0

Views: 346

Answers (2)

Mohammad Hamdy
Mohammad Hamdy

Reputation: 1

Do not use wfastCGI - it is not currently recommended by Microsoft.

If you try uvicorn, it will solve your problem.

Steps:

  1. Install HTTP Platform Handler: https://www.iis.net/downloads/microsoft/httpplatformhandler

  2. Install uvicorn in your virtual environment:

    pip install uvicorn

  3. Update your web.config and restart IIS

     <configuration>
         <system.webServer>
             <handlers>
                 <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
             </handlers>
             <httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\python.log" startupTimeLimit="20" processPath="C:\inetpub\wwwroot\yourproject\.venv\Scripts\python.exe" arguments="-m uvicorn --port %HTTP_PLATFORM_PORT% your_project.asgi:application">
             </httpPlatform>
         </system.webServer>
     </configuration>
    

Upvotes: 0

Roy H
Roy H

Reputation: 1

this happens because your local machine is set to windows-12xx charset instead of UTF-8. I found it most comfortable to use urllib in python to convert the fastcgi url encoding to the desired string.

for example if I'm trying to respond with a Test whose name starts with text appended to the URL (my prod machine charset is windows-1255):

#views.py

import urllib.parse

def searchViewText(request,text): #text received in windows-1255 encoding
    text = urllib.parse.unquote(text,'windows-1255') #

    tests = Test.objects.filter(name__icontains = text)

context={

    
        "tests" : tests,
      
    }
    return render(request,"search.html",context)

Upvotes: 0

Related Questions