IntroductionIn this post, I explain how to count number of visitors in WebSite using ASP.Net and C#.
Hit counters have become an important part of every website. To keep track of the number of visitors in our website we use this. Follow the below steps and do yourself.
Steps :Just follow the steps and get result easily.
Step-1 : Create New ProjectGo to File > New > Project > Select asp.net web forms application > Entry Application Name > Click OK.
Step-2: Add a Database.Go to Solution Explorer > Right Click on App_Data folder > Add > New item > Select SQL Server Database Under Data > Enter Database name > Add.
Step-3: Create a table.Open Database > Right Click on Table > Add New Table > Add Columns > Save > Enter table name > Ok.
Step-4: Add Entity Data Model.Go to Solution Explorer > Right Click on Project name form Solution Explorer > Add > New item > Select ADO.net Entity Data Model under data > Enter model name > Add.
A popup window will come (Entity Data Model Wizard) > Select Generate from database > Next >
Chose your data connection > select your database > next > Select tables > enter Model Namespace > Finish.
Step-5: Add a Class to Save / Get data from database.Go to Solution Explorer > Right Click on Project under solution explorer > Add > New item > Select Class under Code > Enter Name > Add.
Step-6: Add a User Control.Go to Solution Explorer > Right Click on Project under solution explorer > Add > New item > Select Web User Control under Web > Enter Name > Add.
Write the followings code in your page load event for fetch Data(Hit Counter) from Database.
Step-7: Write Code inside Session_Start Event of Global.asax For Add hits into database.
Step-8: Add user control into master page.1st Register UserControl in Master page with below code in the design page at top of the page before <html> tag.
2nd add this Code to add usercontrol into your master page.