1

I'm working with a personal ASP.NET MVC5 project, hosted on Azure

I just realized that, every 5 minuts, Session_OnStart is calledenter image description here

My code looks like this :

public void Session_OnStart()
{
    Guid sessionGuid = Guid.NewGuid();
    HttpContext.Current.Session.Add("_MySession", sessionGuid);
    RegisterSession(sessionGuid);

    logger.Log(LogLevel.Info, "Starting session with guid " + sessionGuid.ToString());
}

The idea is to give a GUID to each user coming to the website, to anonymously follow what he is doing and what pages he opens.

However, I didn't go to my PreProd environment this morning, and the fact it's fired every 5 minutes (more or less 5 seconds) shows that it's a background process or something which accesses to the website.
This didn't happen in localhost testing, only when hosted on Azure

How can I stop this to prevent Azure process to fire Session_OnStart ?
Thank you

user2687153
  • 427
  • 5
  • 24
  • Sounds like a healhcheck... https://learn.microsoft.com/en-us/azure/azure-monitor/app/monitor-web-app-availability#setup ? – Ian Kemp Apr 16 '19 at 12:20

1 Answers1

2

You probably have Always On enabled. You can disable it under
App Service -> Configuration -> General Settings.

Always On. By default, apps are unloaded if they are idle for some period of time. This lets the system conserve resources. In Basic or Standard mode, you can enable Always On to keep the app loaded all the time. If your app runs continuous WebJobs or runs WebJobs triggered using a CRON expression, you should enable Always On, or the web jobs may not run reliably.

PS Have a look at what Application Insights User Flows can do for you.

EDIT:

When my website will be public, will it be reasonnably faster with Always On disabled? It's so slow without it, it's unusable.

The slow start you're experiencing is because the process running your website is shut down after a period of inactivity. Having to restart that process takes some time, hence the slowdown. This is, by the way, because of ASP.NET running in IIS. It's not an Azure specific issue. And like Ian Kemp said, you have to fix your app from being slow.

There are several possible solutions to this issue, like Precompiling your website. Another one would be to switch to ASP.NET Core since it's a lot faster.

More information: Fixing slow initial load for IIS

rickvdbosch
  • 14,105
  • 2
  • 40
  • 53
  • 1
    Indeed, I enabled "Always On" yesterday because my App was really slow. Your solution solves my original question ; however (I'm very new with Azure), when my website will be public (I'm the only one to use it right now), will it be reasonnably faster with Always On disabled ? It's so slow without it, it's unusable (~5 seconds to load a basic HTML page with only one call to DB) – user2687153 Apr 16 '19 at 15:08
  • 1
    "Always On" is not supposed to fix your app being slow, *you* need to do that! – Ian Kemp Apr 17 '19 at 06:01