Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6598721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:23:23+00:00 2026-05-25T18:23:23+00:00

Could anyone helps me by giving the answer for my question. Here is the

  • 0

Could anyone helps me by giving the answer for my question.
Here is the question…
How can we count the number of hits on our website for the day using c#

Thanks,
Bharath

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:23:23+00:00Added an answer on May 25, 2026 at 6:23 pm

    Just create a counter and a persistence way to keep the values. This can be a File or Database.

    The code below is for learning proposes, you should use an existing service for this as it’s much more efficiency and you will not have lock problems if to many hits happen in the same time

    create a new Class for example:

    public static class PageHitCounter
    {
      private String fileTemplate = "dailyHits_{0:yyyyMMdd}.txt";
      private DateTime now = DateTime.Now;
    
      public static void Add() 
      {
        // we'll create one file per day
        // lets append a new user hit to a file
        TextWriter tw = new StreamWriter(getFilename(now), true);
        // let's write the date and something else, f.ex. the browser info
        tw.WriteLine(String.Format("{0:dd-MM-yyyy};{1}", 
                                   now, 
                                   Request.ServerVariables["HTTP_USER_AGENT"]);
        // close the file
        tw.Close();
      }
    
      public static int Count(DateTime day) 
      {
        int hits = 0;
        // let's open the file and count how many lines, 
        //    as we are adding one line per hit
        using (var reader = File.OpenText(getFilename(day)))
          while (reader.ReadLine() != null)
            hits++;
        return hits;
      }
    
      private string getFilename(Datetime day) 
      { 
        return Server.MapPath("~/App_Data/" + String.Format(fileTemplate, day));
      }
    }
    

    in Code:

    Page_Load(...) {
    
        PageHitCounter.Add();
    
    }
    

    when you want to see how many hits, you can use

    PageHitCounter.Count( DateTime.Now );
    

    If you have a lot of pages and don’t want to do this on each one, and assuming your project is WebForms, you can create a MasterPage and append this Add() to the MasterPage OnLoad event or you can create your own page and implement the code.


    As an option to your real problem, you can use Woopra service for live results, I use in some forums and it’s quite lovely see all users, you just need to create an account and use their javascript code in all your footer (normally we use a master page and just append in one file)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anyone help me in assessing why the code below doesn't work. I'm using
Could anyone please help me using C# Api in Z3. I have no idea
Could anyone help me to understand following line of code: sol< ?=f((1<< n)-1,i,0)+abs(P[i])*price; I
Could anyone please help me convert this code to vb.net, I have tried it
Ok so could anyone please help me out with the VB for auto entering
I wonder if anyone could help me with a problem I've been having. I
Im asking to see if anyone could help me with my problem which is
So I'm just learning Forth and was curious if anyone could help me understand
Hey there, was wondering if anyone could help a newbie on SQL and Python.
Could anyone please tell how jre directory help in the running java programs? I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.