-3

I want to know if this example is possible, and what the performance implication would be?

First a question about static content and Page Life cycle. I have a page "Latest_quote". The page is static content that only needs to be updated once an hour. I want it to be a static .html page, that is returned as soon as it is hit so there should be no need to render or parse the html file, so the latency is as low as possible. So it shouldn't be waiting for a script to finish running or parsing the html page just returning static content. But I want a C# script to track how many visitors the page gets, but this script should run after or at the same time as the static content is being returned. Is this possible?

I would also like a timer job to run once an hour that checks and updates the static page. Can I have a timer job run in C# an ASP.NET or Razor site? and would the page go down while it is being over ridden with the new information?

user802599
  • 787
  • 2
  • 12
  • 35

1 Answers1

1

Performance wise static page is a good idea.

For the Job, you can use Quartz.net Task scheduler. Keep this in your Global.asax.cs file, Application_Start method

ISchedulerFactory sf = new StdSchedulerFactory();
        scheduler = sf.GetScheduler();
        scheduler.Start();

IJobDetail jobDetail = JobBuilder.Create<HtmlUpdateJob>() // Class of the job
                .WithIdentity("HtmlUpdateJob") //Name of job
                .Build();
            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("UpdateTrigger") // Name of trigger
                .StartNow()
                .WithCronSchedule("0 0/60 * 1/1 * ? *") //every 60 mins
                .Build();
            scheduler.ScheduleJob(jobDetail, trigger);

The Update Job class:

internal class HtmlUpdateJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        // Update your html here
    }
}

Ensure that you handle scenarios where accessing and writing the html is happens at the same time.

For the user tracking, try to use something external like Google Analytics, it will provide you a client side JavaScript, which will post data to some server page. Google Analytics can provide you more comprehensive data about your visitors.

Alternatively, if you site is hosted on local intranet. You can follow the same approach and create a server side page, which can be called by a client side JavaScript.

Sunil
  • 3,404
  • 10
  • 23
  • 31