Azure Web Apps
Azure Web Apps
Determine the slot in which we're running
Via incoming HTTP header
If your code in an Azure Web App for Linux needs to determine in which deployment slot it's running, then the incoming WAS-DEFAULT-HOSTNAME
HTTP header seems to be the only reliable way. Also confirmed here.
When you're in the production slot, then the value looks like this: someappname.azurewebsites.net
. When you created a slot called stage1
, then this header is someappname-stage1.azurewebsites.net
. The absence of the suffix points to the production slot, otherwise the suffix gives the user-chosen name.
There's a second header called X_SITE_DEPLOYMENT_ID
, but this one contains an identifier like someappname__f375
, which isn't too helpful.
Via system-assigned managed identity
Another, certainly much more clear way, could be using a system-assigned managed identity, assuming you assigned one to all deployment slots. If you fetch an access_token
, then the xms_mirid
claim in the JWT contains the real instance ID, such as
"/subscriptions/.../resourcegroups/.../providers/Microsoft.Web/sites/someappname"
for the production slot, or"/subscriptions/.../resourcegroups/.../providers/Microsoft.Web/sites/someappname/slots/stage1"
for thestage1
slot.
Fetching a managed-identity access_token
from PHP in an Azure Web App for Linux
access_token
from PHP in an Azure Web App for LinuxInside Azure Web Apps for Linux, you can't simply query the instance metadata endpoint, you need a special endpoint from an environment variable https://docs.microsoft.com/en-us/azure/app-service/overview-managed-identity?tabs=dotnet#using-the-rest-protocol
Also api-version must be a special one
Last updated