asp.net-mvcazuremodel-view-controllerenvironment-variables

How and where to define an environment variable on Azure


I have an ASP.NET MVC web application deployed to Azure. I'm reading my setting using the GetEnvironmentVariable(...) method.

The problem is that I can't find a way to define this environment variable in Azure Portal. Where can I do that?

I don't want to have this stuff in a file. Data that will be there are credentials.


Solution

  • I assume you are using Azure App Service (formerly known as Azure Websites).

    To define your own environment variable, click to your site → SettingsEnvironment variables:

    Web App blade navigation with the "Settings" node expanded and "Environment variables" highlighted beneath

    Add an app setting in the "App settings" section:

    Truncated view of the current "Add/Edit application setting" dialog after pressing "+ Add"

    You can verify the value from the debug console.

    Going to https://{your site name}.scm.azurewebsites.net/DebugConsole:

    Enter image description here