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.
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.
It uses the standard OAuth 2.0 client credentials grant. In the Azure portal, select Active Directory > App registrations > New registration.
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
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With