Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get access to azure app service instances directly

I am new to azure. I have an Asp.Net MVC app that is hosted on azure(app service) with two instances, my app uses local cache. Sometimes i need to clear this cache. But the problem is that when i clear cache i actually do this only for one particular instance, and other one still keeps old cache. Is there any way to get access for all instances on app service?

Ofcourse i can run some background task on each instance to achive this, but this does not seems convenient. I would like to have ability to get all IPs and ports of all instances on app service, then create webjob that would hit all instances and clears cache.

like image 453
Volodymyr Gorodytskyi Avatar asked Dec 09 '16 16:12

Volodymyr Gorodytskyi


People also ask

How do I connect to a VM from app services?

Go to App Service plan > Networking > VNet integration in the portal. Select the virtual network your app connects to. Under the routing section, add the address range of the virtual network that's peered with the virtual network your app is connected to.

What method does Microsoft Azure App Service use to obtain credentials?

It uses the standard OAuth 2.0 client credentials grant. In the Azure portal, select Active Directory > App registrations > New registration.


2 Answers

It is possible to do by using ARRAffinity cookie in request. Code sample:

private static async Task<HttpResponseMessage> GetFromInstance(Uri url, string instanceId)
    {
        var cookieContainer = new CookieContainer();
        using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
        {
            using (var httpClient = new HttpClient(handler))
            {
                cookieContainer.Add(url, new Cookie("ARRAffinity", instanceId));
                return await httpClient.GetAsync(url);
            }
        }
    }

One option to get list of instanses ids is via Azure Resource Explorer https://resources.azure.com

like image 100
Volodymyr Gorodytskyi Avatar answered Sep 30 '22 18:09

Volodymyr Gorodytskyi


There is no direct way to connect to a specific instance of a web app. You'd need to either build some type of messaging system to trigger all your app instances to clear their local caches, or shift to a shared cache (which is more in line with hosting in App Services).

like image 35
David Makogon Avatar answered Sep 30 '22 19:09

David Makogon