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)?
-
No, I have decided not proceed this route as it seem to be problematic. – Sean Feldman Oct 01 '13 at 00:32
8 Answers
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.

- 9,034
- 41
- 50
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.

- 1
- 1

- 1,190
- 11
- 21
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.

- 3,136
- 1
- 26
- 35
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

- 81
- 5
-
this is for Azure Web Roles, not Azure Websites (now named Azure Web Apps) – Jonathan McIntire Dec 10 '15 at 21:17
New answer to an old question. I found this worked with .net 6, Azure Function v4, and worked well with hosting on a multi-instance App Server Plan. The value it returns matches the "Server Name" as listed in Application Insights.
var instanceName = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
I then injected this into my logging
Logger log = new LoggerConfiguration()
.Enrich.WithProperty("InstanceName", instanceName)
.MinimumLevel.Debug()
.WriteTo.AzureBlobStorage(
and accessed it by setting it up in my Serilogger output template:
"Logging:OutputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss}][{InstanceName}][{Level:u3}] {Message:lj}{NewLine}{Exception}"
Note: this resolves to null when debugging locally.

- 1,863
- 16
- 15
You can use RoleEnvironment.CurrentRoleInstance.Id

- 1,242
- 1
- 13
- 23
-
This doesn't work on Azure Websites, perhaps because this is for WebRoles? – Sean Feldman Aug 07 '13 at 19:47
Request.ServerName I believe. Just like vanilla IIS

- 265
- 1
- 2
-
That doesn't work. When you have multiple instances (dedicated mode) the server name returned is the same for all instances ([website-name].azurewebsites.net) – Sean Feldman Aug 08 '13 at 14:25
-
`Request.ServerName` isn't a valid property. I assume you meant `Request.ServerVariables[“SERVER_NAME”]`? – Sean Kearney Aug 08 '13 at 14:28