Ravindra, Thanks for the detailed question. As I understand you have tried a few things to get this remedied.
Based on the issue description and my understanding of your scenario - You may check to see if these approaches work and test:
With slight modification in your code, looks like both the cookies are set: Try removing the domain attribute from the ARRAffinity cookie. You can do this by setting the "ARRAffinitySameSite" cookie instead of the "ARRAffinity" cookie. Typically, the "ARRAffinitySameSite" cookie is the same as the "ARRAffinity" cookie, but without the domain attribute.
Here's an example of how to set the "ARRAffinitySameSite" cookie in your response headers:
Set-Cookie: ARRAffinitySameSite=98593782uw92yji3nf0d7dc;Path=/;HttpOnly;SameSite=None;Secure
Note that we've removed the "Domain" attribute from the cookie, and added the "SameSite" attribute with a value of "None". This tells the browser that the cookie can be sent with cross-site requests.
Or
If your requirement fits, to remove the domain attribute from the ARRAffinity cookie, you may use the following code in your Azure Web App:
<system.webServer>
<rewrite>
<outboundRules>
<rule name="Remove ARR cookie domain">
<match serverVariable="RESPONSE_Set_Cookie" pattern="ARRAffinity=.*" />
<action type="Rewrite" value="{R:0}; path=/; HttpOnly; SameSite=None; Secure" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
This code will remove the domain attribute from the ARRAffinity cookie and set it to the current domain.
Additionally info:
Session lost due to ARRAffinity Cookies
(The article from one of my colleague )
App Service scale out requires stateless apps?
(One of my previous discussion thread)
I hope this helps! Kindly let us know if you have any other questions.