Azure app service allows you to auto scale your web app by dynamically adding web server instances to handle the traffic to your web app. Azure app service uses Application Request Routing IIS Extension to distribute your connecting users between your active instances serving up the content. ARR cleverly identifies the user by assigning them a special cookie (known as an affinity cookie), which allows the service to choose the right instance the user was using to serve subsequent requests made by that user. This means, a client establishes a session with an instance and it will keep talking to the same instance until his session has expired.
If you already have a web app on Azure app service , just browse the app and use browser debugger ( click on F12) to see the list of cookies. In the list of cookie you will see ARRAffinity Cookie
There are situations where in keeping the affinity is not desired. For example, if you are getting way too many requests from a single user and the requests going to the same web server instance can overload it. If maintaining session affinity is not important and you want better load balancing , it is recommended to disable session affinity cookie. Follow the steps for either Azure portal or Azure resource Explorer to disable the session affinity cookie:
- Login to the Azure portal
- Browse App Services and select your web application.
- Click on Settings->Application Settings. Find ARR affinity setting under General Settings and click on Off
Azure Resource Explorer:
- Go to Azure resource explorer.
- Click on subscriptions
- Click on your azure subscription in which your web app is located. Click on resourcegroups
- Click on the resource group where the web app is located. Click on Microsoft.Web. Click on sites and Select your web app . Click on Edit to make your changes .
- Search for clientAffinityCookie and set it to false
- Click on PUT to save your changes.
That’s it! You have now disabled the session affinity cookie. You can browse your web app and click on F12 key to access the debugger on your browser to view the cookies generated. For an app without Session affinity cookie you will not see ARRAffinity in the list of cookies.
Without the cookie the requests for your web app, will be distributed evenly across all the instances serving your web app content. You can achieve better load balancing for your web app.