0

Visitors count is resetting for every one hour to zero.

I need total number of visitors for website each day. So that i can store the total count in DB per day.

Protected void Session_Start(Object sender, EventArgs e)
{
    Application.Lock();
    Application["SiteVisitedCounter"] = Convert.ToInt32(Application["SiteVisitedCounter"]) + 1;
    Application.UnLock();
}

Is there any other way to store total number of visitors per day??

D.Dimitrioglo
  • 3,413
  • 2
  • 21
  • 41
sweety
  • 1
  • 2

1 Answers1

1

As MarcusVinicius answered here

You could configure the Periodic Restart Settings for Application Pool Recycling in IIS:

The element contains configuration settings that allow you to control when an application pool is recycled. You can specify that Internet Information Services (IIS) 7 recycle the application pool after a time interval (in minutes) or at a specific time each day. You can also configure IIS to base the recycle on the amount of virtual memory or physical memory that the worker process in the application pool is using or configure IIS to recycle the application pool after the worker process has processed a specific number of requests.

But this has a side-effect of putting the application offline during the time the pool is restarting, so if you have any user connected at that time it will lose its session. This can be minimized by restarting the application at a time you have no users connected, like at dawn.

The following config snippet set the application pool to daily recycle at 3:00 A.M.:

<add name="Example">
   <recycling logEventOnRecycle="Schedule">
     <periodicRestart>
       <schedule>
          <clear />
          <add value="03:00:00" />
        </schedule>
     </periodicRestart>
   </recycling>
 <processModel identityType="NetworkService" shutdownTimeLimit="00:00:30" startupTimeLimit="00:00:30" />
</add>

(OR)

Application is not a permanent object. It is created once your application starts (e.g the first session is started) and disposes of after your application pool times out. You can either persist your variable or simply change Idle time-out parameter in your AppPool

(IIS=>Application Pools => your AppPool (or DefaultAppPool if you haven't defined one)=> Advanced Settings => Idle Time-out).

Community
  • 1
  • 1
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115