question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Web.config environment variables missing in Azure

See original GitHub issue

TL;DR Some environment variables present in the web.config (like ROOTDIR) generated by PTVS are missing in Azure. This causes a deployment to “fail” because even tho the code is deployed, the site doesn’t run. Replacing the variables with hardcoded values solves the issue.

Am I supposed to have those variables set in my Web App automagically by Azure or am I supposed to treat those variables as placeholders and edit my web.config with the appropriate values?


Howdy,

I had an issue happening to me every time I tried to use PTVS and Azure, so I just downloaded the latest version both Visual Studio and PTVS, did a File->New Django project and published it to an Azure Web App.

This is the web.config generated by PTVS:

<?xml version="1.0"?>
<!-- Generated web.config for Microsoft Azure. Remove this comment to prevent
     modifications being overwritten when publishing the project.
-->
<configuration>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <appSettings>
    <add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="%ROOTDIR%\env\Scripts\python.exe" />
    <add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()" />
    <add key="PYTHONPATH" value="%ROOTDIR%" />
    <add key="DJANGO_SETTINGS_MODULE" value="djangotest.settings" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="%INTERPRETERPATH%|%WFASTCGIPATH%" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
    <rewrite>
      <rules>
        <rule name="Static Files" stopProcessing="true">
          <conditions>
            <add input="true" pattern="false" />
          </conditions>
        </rule>
        <rule name="Configure Python" stopProcessing="true">
          <match url="(.*)" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

As you can see, this config file “depends” on the presence of some variables to work, namely ROOTDIR, INTERPRETERPATH and WFASTCGIPATH.

Those variables don’t seem to be present on my Azure Web App, even after I properly configured the site to use python 3.4, but if I replace those variables with hardcoded values (ROOTDIR with D:\home\site\wwwroot\ and so on) then the Web App works beautifully.

Tested with both python 2.7, 3.4 and 3.5 (using extensions) and it’s the same thing no matter which python version: no variables present.

Am I supposed to have those variables set in my Web App automagically by Azure or am I supposed to treat those variables as placeholders and edit my web.config with the appropriate values?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zoobacommented, Oct 28, 2016

We already have issue #1684 to fix a genuine bug in the template, so I’ll add a note there and close this. Thanks for the feedback!

1reaction
zoobacommented, Oct 28, 2016

Also see this post https://blogs.msdn.microsoft.com/pythonengineering/2016/08/04/upgrading-python-on-azure-app-service/

It has some sample web.configs for App Service that are much shorter. The code we generate is far more complicated than it needs to be (if you know how to edit it manually, that is 😃 ).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure WebApp AppSetting not overriding my Web.Config ...
My ASP.NET Core web app defines the environment variable ASPNETCORE_ENVIRONMENT in the web.config file. It is is to DEVELOPMENT , which means ...
Read more >
Environment variables and app settings in Azure App Service
In Azure App Service, certain settings are available to the deployment or runtime environment as environment variables.
Read more >
web.config file
The web.config is a file that is read by IIS and the ASP.NET Core Module to configure an app hosted with IIS.
Read more >
Missing or undefined environment variables with Node on ...
We specify environment variables in GitHub Actions using the env property. More on that can be found here: name: Build and deploy Node.js...
Read more >
Configure function app settings in Azure Functions
Learn how to configure function app settings in Azure Functions. ... Connection strings, environment variables, and other application ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found