Windows Azure Websites - Get Instance Identifier - azure

What's a possible way to determine on an Azure website with multiple instances what instance is responding (some ID or other piece of unique info)?

The following environment setting will have the instance id the current request is running on: WEBSITE_INSTANCE_ID.
You'll also receive this id as a cookie in the response named: ARRAffinity.
You can also use this information to get back to that specific instance, see: http://blog.amitapple.com/post/2014/03/access-specific-instance/ for more information about it.

Microsoft Azure provides many environment variables for Azure Web Apps (formerly known as Website), including the following:
WEBSITE_SITE_NAME - the name of the site.
WEBSITE_INSTANCE_ID- the id representing the VM that the site is running on.
etc
See Azure Runtime Environment by David Ebbo for more details.

You can use Server.MachineName to get the name of the server.

2022-06-06
Configuration of Web App
How to find Instance
1.This is an instance ID.
2.Go to see the environment
3.Find which variable is pl1sdlwk0001WS, and COMPUTERNAME is that you want.

Set up InstanceInputEndpoint in configuration. This will allocate ports from the given port range for each instance, then you can visit a instance through the port.
For more information about InstanceInputEndpoint: http://msdn.microsoft.com/en-us/library/windowsazure/gg557553.aspx

You can use RoleEnvironment.CurrentRoleInstance.Id

Request.ServerName I believe. Just like vanilla IIS

Related

Same IIS local host labelled different name when loggin using differenit Alias

When I logged in to the same IIS using different alias, the name on the local host is different. I didn't change or do anything differently since the creation of this IIS. How it shows different names on different login account is unexplainable.
May I know if I make change on my end to match the one on the role account, it will not break things on this server. I checked with other admins, they see what the role account sees. I am the only person that has name mismatched (it shows DEV instead of PROD).
This is what I see when I log in as me under IIS connection DEVAPP01 (.../Luu). And this is what I see when I log in as a role account PRODAPP01 (..../roleAccountp1 So sorry the website doesn't allow me to post image yet. I'm new to stackoverflow and hope I can get some advice here.
Changing the label is easy but I would like to make sure it doesn't break anything since this is PROD environment. Thx
Regards,
I figured this out (with the help from our cloud team of course). I was told that at one point, the server was named DEVAPP01, later it was renamed to something else and I still connected to the wrong name on the same server. To solve this problem, I:
In the IIS under connection, select Connect to Server and put in the right IIS name which is PRDAPP01, once I got in there, I saw two IIS 1) DEVAPP01 and 2) PRDAPP01
Select the wrong IIS name which was DEVAPP01 and right click and select Remove Connection (this option seated below Refresh)
Problem solved!!!
Thanks to my great cloud team from my company.

How can I get the "real" Azure App Service slot instance name?

I'd like to know how I can get a unique identifier for the "slot instance" that an Azure App Service slot has loaded into it.
Note that I am not referring to the name of the slot.
For example:
My Azure App Service has two slots named "App" (Production) and "App-Staging" (Staging).
I then deploy version 1 of my project to the "App" slot.
I then deploy version 2 of my project to the "App-Staging" slot.
I then perform a Slot Swap operation from the Azure Portal:
Both instances of my app are running simultaneously (imagine they run in a container of some kind).
Both "containers" are immediately "detached" from their associated slot while still running.
Both "containers" are then immediately re-attached to the opposing slot.
i.e. version 1 stops receiving HTTP requests for app.azurewebsites.net and suddenly starts receiving requests for app-staging.azurewebsites.net.
and version 2 stops receiving HTTP requests for app-staging.azurewebsites.net and suddenly starts receiving requests for app.azurewebsites.net.
In order to investigate some issues I was having, I created a text file at D:\home\SlotName.txt. In the "App" slot I entered "SlotA" and in the "App-Staging" slot I entered "SlotB".
This SlotName.txt moves with the application instance, and allows my application to detect which filesystem or "container" instance it's living in - and this doesn't change when a slot-swap is performed.
I find this information essential when trying to uniquely identify deployments or when investigating logging continuity issues (as the staging slot won't be logging production data, for example).
However, my SlotName.txt file seems like a hack - but I can't see any information in the Environment Variables for my app's instance that reveals the same information.
Environment variables do reveal the slot name, e.g. "App" and "App-Staging" which is mutable - of course, but it doesn't uniquely identify the "container" or filesystem instance that the app is deployed into.
Here's the two Kudu Environment pages from the Production and Staging slots - notice that the values are either identical (like Machine name), slot-specific, or refer to the deployed application code and none of them refer to the filesystem / container instance they live in:
Is there any way to get this information without using my SlotName.txt trick?
The answer hiding right under my nose - and different terminology.
What I was calling a "slot instance name" is actually referred to as a "Deployment Id" (I know this is an overloaded term as it's also used in the context of Azure's (now legacy) "Cloud Services" PaaS too).
This information is visible in the Kudu environment page and is also an exposed as an environment-variable: WEBSITE_DEPLOYMENT_ID.
The WEBSITE_DEPLOYMENT_ID value is of the form {SiteName}[__{Random}], with the __{Random} prefix omitted for the first deployment space.
If you look closely at the screenshot I posted, you'll notice the left-hand screenshot has the site-slot-name Site1__e928 whereas the right-hand screenshot is of the "first" slot-space and so its name is just Site1.
It is unfortunate that this information is not documented by Microsoft publicly - at least so far as Google can see (searching for the term right now yields zero useful relevant results):
Mystery solved!
You have something called deployment slot setting values as shown in below image:
Attach a key-value pair in each slot with different value.
Here, this setting sticks to the specific app, even if you swap.
This can be trick you're looking for.
Source

How do i use azure app service env variables inside my application?

i'm trying to setup my project in azure. For this i created an app service and under settings/configuration i added some "Application Settings", which in my understanding are environment variables. However i deployed my docker image which azure pipelines and everything is okay, but when i connect through ssh to the instance and call 'env' i don't see any of my environment variables.
From the documentation i should be able to call them inside php as every other env variable (getenv..). Maybe i miss something or my understanding of this app settings are incorrect.
Would be great if somebody has an idea about what is wrong, if you need more informations hit me up.
Partly, you did not make mistake on the way of accessing setting/configuration which set as environment variable. The getenv() is correct.
when i connect through ssh to the instance and call 'env' i don't see
any of my environment variables
I think this issue may caused by your script. When you access these setting keys, do not lost Prefixed. This is the important way to access and get these environment variable. For example, if you want to access app settings, the name of the corresponding environment variable should prepended with APPSETTING_.
At this time, the sample script for PHP script should be:
<?php
$appsetting = getenv('APPSETTING_{Key}'); echo $appsetting;
?>
Note: The {key} is the key name you configured in Azure app service.
For the configuration which under Connection Strings, it should be added with other prefixed. As you know, when you create these connection strings, you need to choose Type:
For these setting, the connection strings are available as environment
variables, prefixed with the following connection types:
SQL Server: SQLCONNSTR_
MySQL: MYSQLCONNSTR_
SQL Database: SQLAZURECONNSTR_
Custom: CUSTOMCONNSTR_
For more details, check this doc: https://learn.microsoft.com/en-us/azure/app-service/configure-common#configure-connection-strings
Setting Environment Variables
In Azure Portal, locate your app service
On the left pane, click Configuration
Under Application settings, click "New application setting"
Fill in the name and value for the environment variable
Click "OK", then at the top, click "Save"
Accessing Environment Variables
With PHP
Replace ENV_VAR_NAME with your own environment variable name.
$var = getenv('ENV_VAR_NAME');
With CLI - Linux
You can use your preferred SSH client, but in this case I'll use the one in Azure Portal.
In Azure Portal, locate your app service
On the left pane, click "SSH"
Click "Go"
Type printenv ENV_VAR_NAME, replace ENV_VAR_NAME with your environment variable.
I found this article which explains a little bit more how the whole stuff works.
https://omgdebugging.com/2018/10/05/how-to-export-environment-variables-in-azure-web-app-for-containers/
However i sticked to this article and used the provided workaround. If somebody knows a better solution, please let me know

How to check if website name provided is available and free in Azure SDK for dot net

I'm trying to create a web app in azure using
azure.WebApps
.Define(name)
.WithExistingWindowsPlan(plan)
.WithExistingResourceGroup(resourceGroupName)
.CreateAsyn()
Since the name must be globally unique, how can I check if the name exist already?
Similar to Erndob's comment there - I'll extend it by saying that catch the error and look into the specifics. If it's failing with a name not unique error - that's your check failing right there. Any other failures should be treated differently.

How are Applications Removed from the IIS Application Pool?

We've got a new server, and I am trying to set it up for our website.
I got a new application for the engineers set up in the Application Pools called eng_app, then added our applications to it.
Now, we have been given an external drive that these applications need to be on, but I can't seem to edit or delete the existing applications.
I tried following the Microsoft Technet Article • Remove an Application (IIS 7) but, as you can see in the screenshot, those are incorrect.
C:\Windows\System32\inetsrv>appcmd delete app "eng_app/drawing"
ERROR ( message:Cannot find APP object with identifier "eng_app/drawing". )
C:\Windows\System32\inetsrv>appcmd delete app "/eng_app/drawing"
ERROR ( message:Must specify the APP object with identifier or "APP.NAME" parameter. )
Could someone tell me what I missed here?
Using Powershell
Go to folder
cd C:\Windows\system32\inetsrv
List all applications to get the correct APP.NAME
.\appcmd list app
Delete the application using fullname for <APP.NAME>.Ex.: "Default Web Site/The.Application".I mean, you must put it with web site name including the double-quotes.
.\appcmd delete app <APP.NAME>
OK, it looks like you can't do it either through the command line or using the Application Pool interface.
After stopping the webservice, what I did was:
go down to the list of Sites and select my application from the list,
click Basic Settings...
change the Application pool with the Select... button and edit the Physical path
Afterwards, you can restart the webservice.
There might be a better way, but this is how I did it.
appcmd delete app eng_app/drawing

Resources