我已将无状态 Web 应用程序部署到 Azure 应用服务,并在应用程序设置中禁用了 ARR Affinity。是否可以禁用此功能,但针对特定请求启用它?
我在 2016 年遇到了benjaminperkins 的一篇文章,该帖子表明可以通过添加“Arr-Disable-Session-Affinity”标头来为单个请求禁用此功能,但我想要反过来,“Arr-Enable-Session-亲和力”。
我希望能够向单个实例发出请求,以在远程操作后预热内存中的缓存。我了解如何在启用 ARRAffinity 时构建对 App Server Web 应用程序实例的 URL 请求,但这对我不起作用,因为我不想全局启用它。
这是我想做的一个例子:
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);
在应用服务上禁用 ARRAffinity 时,有没有办法做到这一点?