15

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)?

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80

8 Answers8

23

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.

Amit Apple
  • 9,034
  • 41
  • 50
3

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.

Community
  • 1
  • 1
Oleg Burov
  • 1,190
  • 11
  • 21
1

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

1

2022-06-06

Configuration of Web App

enter image description here

How to find Instance

1.This is an instance ID.

enter image description here

2.Go to see the environment

enter image description here

3.Find which variable is pl1sdlwk0001WS, and COMPUTERNAME is that you want.

enter image description here

Jess Chen
  • 3,136
  • 1
  • 26
  • 35
0

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

sqybi
  • 81
  • 5
0

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.

Larry Smith
  • 1,863
  • 16
  • 15
-2

You can use RoleEnvironment.CurrentRoleInstance.Id

bhavesh lad
  • 1,242
  • 1
  • 13
  • 23
-3

Request.ServerName I believe. Just like vanilla IIS

Nir Mashkowski
  • 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