I have a project requirement that when a request is processed by a specific MVC controller that ARR Affinity is turned off. After trying and failing to get this to work in the cloud I created a simple Test Application that proves that it does not work. Per Disabling ARR's Instance Affinity I just need to add a response header. So to test this I created a default .NET framework 4.8 MVC web application, and modified the home controller as indicated below:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = $"Your index page.'{System.Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")}'";
Response.Headers.Add("ARR-Disable-Session-Affinity", "True");
return View();
}
public ActionResult About()
{
ViewBag.Message = $"Your application description page.'{System.Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")}'";
Response.Headers.Add("ARR-Disable-Session-Affinity", "True");
return View();
}
public ActionResult Contact()
{
ViewBag.Message = $"Your contact page.'{System.Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")}'";
Response.Headers.Add("ARR-Disable-Session-Affinity", "True");
return View();
}
}
I added this code <h3>@ViewBag.Message</h3> to the index.cshtml page and deployed to an Azure Windows web application with 2 instances. This is what I see when I navigate to every page using the menu.
As shown the first page might hit a particular instance. Then that instance changes. After that the instance never changes. Does anyone have any ideas of what I am doing wrong if anything or does this not work anymore under an Azure Windows Web Application?



I tried your code in my environment and got the Web App instance ID in my browser.
Code :
index.cshtml :
I publish the above code to the Azure Web App Services below:
I added two instance counts to the Web app below.
By default, ARR affinity is set to be on.
Then, I browsed the Web app in the Azure portal and got the same instance ID below,
Output :
If I set the ARR affinity to Off, I got different instance ID's below.
Output :