2

I have stateless web applications deployed to Azure App Service and have ARR Affinity disabled in the Application Settings. Is it possible to leave this disabled, but enable it for specific requests?

I came across a post by benjaminperkins from 2016 that indicated it was possible to disable this for individual requests by adding a "Arr-Disable-Session-Affinity" header, but I would like the reverse of this, "Arr-Enable-Session-Affinity".

I would like to be able to make requests to individual instances to warm-up an in-memory cache following a remote operation. I understand how to build a URL request to an App Server web app instance when ARRAffinity is enabled, but this won't work for me as I do not want to enable this globally.

Here is an example of what I would like to do:

ServiceClientCredentials serviceCreds = 
   await ApplicationTokenProvider.LoginSilentAsync(this.config.ADTenant, this.config.ADApplicationId, this.config.ADKey);

ResourceManagementClient resourceClient = new ResourceManagementClient(serviceCreds);
resourceClient.SubscriptionId = this.config.SubscriptionId;
WebSiteManagementClient webClient = new WebSiteManagementClient(serviceCreds);
webClient.SubscriptionId = this.config.SubscriptionId;

string urlPath = "custompath/";
SiteInner site = 
   webClient.WebApps.List().Where(a => a.Id == "webapp id").FirstOrDefault();
IList<SiteInstanceInner> instances = 
   webClient.WebApps.ListInstanceIdentifiers(site.ResourceGroup, site.Name).ToList();

SiteInstanceInner instance = instances.FirstOrDefault();

// these are initialized as a singleton, inline here as an example
HttpClientHandler handler = new HttpClientHandler() { UseCookies = false };
HttpClient httpClient = new HttpClient(handler, disposeHandler: false);

httpClient.Timeout = new TimeSpan(0, 0, 30);
webClient = await GetWebsiteClientIfNull(webClient);

Uri url = new Uri($"http://{site.DefaultHostName}/{urlPath}");

HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, url);
message.Headers.Add("Arr-Enable-Session-Affinity", bool.TrueString);
message.Headers.Add("Cookie", $"ARRAffinity={WebUtility.UrlEncode(instance.Name)};");

HttpResponseMessage response = await webClient.HttpClient.SendAsync(message);

Is there a way to do this when ARRAffinity is disabled on the App Service?

Steve B
  • 161
  • 2
  • 13
  • I apologize from the start, i have nothing good to contribute here but i must make one observation: your application is neither stateful nor stateless. Your application is Schroedinger's application. – evilSnobu Oct 27 '17 at 19:30
  • When you disable it, the cookie doesn't get returned to the client. The thing I'm not sure off is whether the cookie would still be honored by the server if the client was to still pass it in the request. Did you try this? – David Ebbo Oct 27 '17 at 19:31
  • 2
    David - yes, I tried the code above which includes the ARRAffinity cookie in the request and it doesn't seem to work. I made a remote call to a page that would return the machine name in an app service that had four instances running, each call would seem to round-robin through the four machine names in the response, even though the cookie was being sent for a single instance. – Steve B Oct 27 '17 at 21:22
  • It seems that we have no way to that, as it is disabled from the server side. – Tom Sun - MSFT Oct 31 '17 at 05:08

0 Answers0