Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get app service name in azure programmatically

Tags:

azure

Simple question, hopefully a simple answer :)

How to I get the app service name, displayed as "test-webapp" in the picture below, from code (C#)? (any other identifier of a specific app service also works).

I have multiple app services, running same code. So I want to be able to express

if(appServiceName == "test-webapp")
{
    //take a specific value from web.config and run with it
}

see image

like image 904
Cowborg Avatar asked Mar 13 '18 09:03

Cowborg


People also ask

What is app service name in Azure?

Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends. You can develop in your favorite language, be it . NET, . NET Core, Java, Ruby, Node. js, PHP, or Python.

How do I find my Azure App Service plan?

In the Azure portal, search for and select App services and select the app that you want to move. From the left menu, select Change App Service plan. In the App Service plan dropdown, select an existing plan to move the app to.

What is app service plan name?

An App Service plan defines a set of compute resources for a web app to run. These compute resources are analogous to the server farm in conventional web hosting. One or more apps can be configured to run on the same computing resources (or in the same App Service plan).


1 Answers

You can get it from the WEBSITE_SITE_NAME environment variable.

To get the variable, use something like:

string siteName = System.Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")

You can see a list of environment variables available here: https://github.com/projectkudu/kudu/wiki/Azure-runtime-environment.

like image 182
juunas Avatar answered Oct 03 '22 06:10

juunas