azure WEBSITE_NAME appsetting is missing - azure

Reading through the azure documentation and various posts on here, i understand there should be a number of settings available to web apps running on azure, among them WEBSITE_HOSTNAMEand WEBSITE_SITE_NAME. These should also overwrite any existing configuration appsettings with same key.
When i attempt to run my app, it is reading the key from the config file (i.e. its not being overwritten by azure). If i remove the value from the config, i get an exception about not being able to pick up a config value.
Is there a step im missing? Are these values only available at certain tiers?

Those values are only available as environment variables, so you'll need to read them from there.
App settings set in the Web App blade override settings and become env variables, but these are just environment variables.

Related

Lookup Azure application name from within a running function app

Is it possible to lookup the application name for an Azure app as it runs, i.e., get the information about that is displayed in the Azure portal? In the example below, I'd want something to tell me from within the application that I am running sitemap-prod-eastus.
I've been looking at the Azure Context object but not seeing what I need. There is an invocation ID, a name for the function, a directory - not the info in this window.
Maybe this can be done through Azure Application Insights?
I am working in Node JS.
I've not seen anything that would expose this to a function app. That said, there is one sort of workaround that you could do which would work - go to the Configuration blade for the function app, Application settings tab, and add a configuration key like function_name and set its value to the name of your app. Your app could then just read it out of configuration.
It's an extra step, but if you're doing it with something like ARM or Terraform, it's just another configuration entry with a variable you already declared to set up the app in the first place.
Answering my own question: Azure provides WEBSITE_SITE_NAME in the runtime environment that matches the name of the function app.

Azure App Service configuration settings (environment variable) does not work

I created an environment variable in Azure App Service. However, I'm not able to pick the value from Azure while it is published.
So I added it to the appsettings.json, and it works.
My question would be, if I add an environment variable in Azure configuration settings, shall I add it in the appsettings.json as well, or is having it in the Azure environment settings enough?
When I navigate to
https://your-web-name.scm.azurewebsites.net/Env.cshtml
I can clearly see the variable is present there. Why is this not being picked up in the code? Am I doing something wrong?
appSettings["MailKitPassword"] <-- This is not being picked up, so I have to hard-code it.
In order to retrieve it you should use Environment.GetEnvironmentVariable("APPSETTING_MailKitPassword")
As Thiago Mentioned, you need to use GetEnvironmentVariable method to retrieve the AppSettings values,
so your code should be
Environment.GetEnvironmentVariable("APPSETTING_MailKitPassword")
However i would recommend you to store the passwords in Azure KeyVault.

Azure Webapps for Containers connection string in environment variables

My app running in a docker container on Azure Webapps for Containers tries to access a connection string through an environment variable. I've added it to the Application Settings in the Azure UI but I can't access it through my code, specifically my ASP.NET Core application is returning null.
I know that the logs won't show it being added as a -e connstring=myconnstring argument in the docker run command, but it should never the less be present in the container.
It turns out, by using the Advanced Tools -> Environment Kudu service in Azure, the connection string environment variable names were being prefixed with SQLAZURECONNSTR_.
I know it is a convention to have these kind of prefixes on environment variables when reading them with the .NET Core environment variable configuration provider as described here, but quite why Azure adds these prefixes automatically, apparently without documenting this behaviour anywhere, is unclear to me.

How to set azure-web-app-service application settings for node.js app via deployment

Is it possible to set azure app service application settings (especially env variables) via deployment?
We are using local git repositories to deploy our NodeJS application to different azure appservices.
There are several environment variables required to run the application. I'd like to know if there is a way to insert those automatically while deploying the application so I do not have to set them manually for each application.
If its possible how does azure handles changes in the environment settings if I changed a variable afterwords? For example if I have sensitive data that I have to enter after deployment directly into the env variable?
Here's an example. Variables: Name=InitialValue
VAR_1=Test1234
VAR_2=Hello World
USERNAME=
PASSWORD=
USERNAME AND PASSWORD need to be empty an filled afterwords directly via azure portal. Now I redeploy. What happens to my USERNAME and PASSWORD entries? What happens if I change the value of VAR_1? In this case I'd like to have the environment variable changed.
In azure app service the environment variables can be set via Application Settings > App Settings.
It has a 'key-value' format where you can enter the variable name and its value.
Then in the code you can read them as "process.env.Username " and so on.

Azure Application Settings not overriding my appsettings.json file values

I have tried adding DefaultConnection from my appsettings.json file to Azure's Application Settings but Azure will not override the connection string.
Any article or blog I can find states that all I should need to do is add the connection string name as it states in the appsettings.json file and Azure should do the rest (e.g. https://tehremo.wordpress.com/2016/10/07/override-connection-strings-app-settings-in-asp-net-core-and-azure-app-service/) however when the application is published it is using my local connection string.
My Startup.cs file looks like the following:
NOTE: I am publishing using VSTS continuous delivery with "Deploy Azure App Service" release task.
I just had a similar problem (the problem was with PostgreSQL connection string type, I had to change it to custom) and now it works for me, so these are the pieces:
This is my appsettings.json file. I have a value for 'Psql' set in my appsettings.Development.json, but in the appsettings.json it is left empty.
These are the settings which are set in the Azure portal. Please note, that there are two ways to override the connection string.
This is the part of my Startup.cs file. Pay attention to the order of how the settings are applied in the Startup constructor and the way I get the connection string in the ConfigureServices method (GetConnectionString is a standard extension method).
Additional info from my comments below:
Azure GUI (Connection strings, Application settings) uses environment variables internally, so the appsettings.json will stay the same.
If there is a need for an appsettings.json's value to be overwritten during VSTS release activity (before it will be published to Azure), Colin's ALM Corner Build & Release Tools can be used. Here are the links to Colin's ALM Corner Build & Release Tools and tutorial.
Thanks #pasul, your help was much appreciated and helped me find an alternative solution. In order to deploy using VSTS task and replace application settings, you will need to add variables to the release task and pass into the task the json file in question for variable substitution.
When in "Deploy Azure App Service" release task you should see a "File Transforms and Variable Substitution" section. In here you will supply the path to the json file you want to swap variable values.
Then you will need to click on the options button on the release environment. You will see an option to configure variables in the pop out menu.
From here you can add the json property you want to modify as a variable. In my case the connection string. Which will look like the following:
"ConnectionStrings.DefaultConnection"
Then just put in your connection string value. VSTS will then swap out these values for you when deploying.

Resources