How to Detect If Your Application is Running in Azure App Service
source link: https://edi.wang/post/2023/12/14/how-to-detect-if-your-application-is-running-in-azure-app-service
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Detect If Your Application is Running in Azure App Service
Original
Edi Wang
12/14/2023, 8:34:41 AMProblem
An application needs to know if itself is running in Azure App Service, so that it can apply special logic and optimization for Azure.
Solution
When deploying an application to Azure App Service, the platform automatically assigns a set of environment variables that can be accessed by the application code.
To view the complete list of environment variables applicable to your application at runtime, you can navigate to the "Advanced Tools" blade within your App Service Instance.
Then, go to "Environment" page. You will see the entire list here. Among them, are a few environment variables that are suitable for identify if the application is running on Azure App Service.
WEBSITE_SKU
WEBSITE_SITE_NAME
WEBSITE_HOSTNAME
Now, in our code, we can try to get the values of those environment variables, example code for ASP.NET Core Razor Page is like:
<tr>
<td>@SharedLocalizer["Azure App Service"]</td>
<td class="text-muted">
WEBSITE_SKU : @Environment.GetEnvironmentVariable("WEBSITE_SKU") <br />
WEBSITE_SITE_NAME: @Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME") <br />
WEBSITE_HOSTNAME : @Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME") <br />
REGION_NAME : @Environment.GetEnvironmentVariable("REGION_NAME") <br />
</td>
</tr>
Example result:
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
Recommend
-
41
Azure App Service is a way to host your web application in a container without having to think about the server. It’s the same PaaS concept as
-
9
Gunnar Peipman – Programming BlogASP.NET Core, Blazor, .NET, Azure, SharePoint, IoT A portal focused on Operatio...
-
8
How to deploy Angular app to Azure App Service running Linux from GitHub
-
10
Laravel is an open-source PHP framework designed to make developing web apps mush easier and faster through built-in features. It is based on the MVC design pattern.In this article, I will show you how to deploy a Laravel application t...
-
8
Deploying to Azure Arc via Azure Application Services Part 2: Running Azure Functions Anywhere
-
1
Learnings from the field – Running Fluent Bit on Azure Kubernetes Service – Part 1 This is the first part of a three-part series about “Learnings from the field – Running Fluent Bit on Azure K...
-
4
Learnings from the field – Running Fluent Bit on Azure Kubernetes Service – Part 2 This is the second part of a three-part series about “Learnings from the field – Running Fluent Bit on Azure...
-
29
Learnings from the field – Running Fluent Bit on Azure Kubernetes Service – Part 3 This is the second part of a three-part series about “Learnings from the field – Running Fluent Bit on A...
-
10
This post will cover getting set up to run Puppeteer on Azure App Service Linux. Overview Puppeteer is a Node.js library which lets you access Chrome/Chromium through e...
-
5
Abstract Azure App Service expanded its support to
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK