Change EnvironmentName in IIS (vNext MVC6) - iis

I try to use MVC6 and I want to use new feature "Changing configs by environment" in my apps
So as far as I understand I can choose proper config by changing environment variable ASPNET_ENV. I know two ways to change value of this variable
1) I change variable at Debug tab at Project Properties
2) I change variable at Azure Portal for my Azure Web Site
But how can I specify this variable in IIS after publishing website?

You can set specific user for the AppPool of your website, and then set environment variable for the user.

Related

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.

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.

How can I view the final appSettings values on an Azure App Service web app?

I have an ASP.NET MVC app deployed to Microsoft Azure App Service and am having some trouble with the appSettings and connectionStrings values.
I have some values set in the web.config and some values overriding them in the Application Settings tab of the App Service. I want to quickly and easily view the final values to check that the settings are being picked up correctly.
How can I do this?
Note: I've tried using az webapp config appsettings list but this only seems to bring back what is configured in the Application Settings of the App Service and not the merged results of combining with web.config.
No Azure API will return values that include settings that come from your web.config file.
The only way to get this is to ask the config system within your own runtime. e.g. Use code along these lines:
foreach (string name in ConfigurationManager.AppSettings)
{
string val = ConfigurationManager.AppSettings[name];
...
}
foreach (ConnectionStringSettings settings in ConfigurationManager.ConnectionStrings)
{
string connStr = settings.ConnectionString;
string provider = settings.ProviderName;
...
}
This will give you the effective values that are applied to your app.
You may also use the following blades in Azure Portal (under Development Tools section):
Console
In order to see the file, you may use type command, e.g.:
type web.config
Advanced Tools
This points to the Kudu service.
You may see files deployed when navigating to Debug Console > Choose either CMD or PowerShell. Then navigate to your config directory (e.g. site/wwwroot) and choose to either download or edit file.
App Service Editor
App Service Editor is a relatively new tool in Azure toolset. Default view is a list of files, so you can browse all hosted files, including configuration ones.
You can view all of your runtime appSettings, connection strings and environment variables (and more..) using azure KUDU SCM. if your application address is "https://app_name.azurewebsites.net" you can access it in the address "https://app_name.scm.azurewebsites.net" or from azure portal
With kudo REST API, you can get the settings, delete or post them in this address https://app_name.scm.azurewebsites.net/api/settings
kudo wiki

azure WEBSITE_NAME appsetting is missing

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.

How can I set the deployment path for an iisApp Provider using MsDeploy?

I am creating Web Deployment Package zip files for my Web Applications
I found I am able to specify the Site Name of the application by including a pubxml during the packaging of my site and using the PublishProfile property during the build to specify that profile.
The pubxml has <DeployIisAppPath>WebSiteName</DeployIisAppPath> in it and that creates the site name as seen in the IIS Management screen.
I'd like to specify the location on disk of the website when it is deployed to a server that doesn't already have this app installed.
What property can I use to do this?
I see that I could use -replace arguments as shown here: Specify different path for provider iisApp when creating package with msdeploy but I would rather the value be set in my pubxml.
You have two options:
Choose the checkbox for "Include IIS settings ...". When you do this a text box will light up with the title "physical Path of web application on destination server". Using the value for the parameter that is generated for this you can modify the destination app path.
Another option for you is to use msdeploy.exe directly and recreate the package using "apphostconfig" provider instead of iisApp provider and then parameterize the application path on the destination server.

Resources