Automatic ASP.NET Page

I thought for a long time about the idea of ​​some kind of automatic cleaning page that performs the usual maintenance tasks and is called from the scope of the current page by calling a 1x1 pixel gif with an asp.net page as an src parameter. However, one thing that I have never decided is how to process the execution time of such a page so that it does not execute with every request, maybe like ... every fifth request. or every 30 minutes or some other interval.

What do you think about creating such a mechanism?

+3
source share
5 answers

, , , , , . , , , , . , , , .

+4

, global.asax - , - N- . , - , - ,

void Application_Start(object sender, EventArgs e) 
{
    // Code that runs on application startup
    Application["Sessions"] = 0;
}

void Session_Start(object sender, EventArgs e) 
{
   // Code that runs when a new session is started
   Application.Lock();
   Application["Sessions"] = (int)Application["Sessions"] + 1;

   if ((int)Application["Sessions"] % 5 == 0)
   {
     DoSomething();
     Application["Sessions"] = 0;
    }
    Application.UnLock();
}

- , script GIF . .

+4

, Windows? ASP.NET. , SQL Server, , SQL Server .

+1

I set the timer and started the cleanup task when the timer fires. If you want to configure cleaning by the number of requests, you can make a shorter timer interval, and then check the number of requests when the timer is triggered; if the number of requests is too low, skip the cleanup.

0
source

Source: https://habr.com/ru/post/1699593/


All Articles