Why does ARR-Disable-Session-Affinity not work in Azure Web App

219 Views Asked by At

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.

enter image description here

enter image description here

enter image description here

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?

1

There are 1 best solutions below

6
Aslesha Kantamsetti On

I tried your code in my environment and got the Web App instance ID in my browser.

Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace arrafinity.Controllers
{
    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();
        }
    }
}

index.cshtml :

<h3>@ViewBag.Message</h3>

I publish the above code to the Azure Web App Services below:

enter image description here

I added two instance counts to the Web app below.

enter image description here

By default, ARR affinity is set to be on.

enter image description here

Then, I browsed the Web app in the Azure portal and got the same instance ID below,

Output :

enter image description here

enter image description here

enter image description here

If I set the ARR affinity to Off, I got different instance ID's below.

enter image description here

Output :

enter image description here

enter image description here

enter image description here