Monday, 9 December 2013

Count Number of Visitors in Website using in C#

Follow these steps :1,
Open Visual Studio à Create New Website à Right click on Solution Explorer à Select Add New Item à Select Global Application Class file and click 

Step :2,

In Global.ascx page do these changes

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

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

Step:3, in aspx page

<html xmlns="">
<head runat="server">
<form id="form1" runat="server">
<b>No of Visits in your application:</b>
<asp:Label ID="lblUserCount" runat="server" ForeColor="Red" />

Step:4, in aspx.cs  code behind page

protected void Page_Load(object sender, EventArgs e)
lblUserCount.Text = Application["NoOfApplicationVisitors"].ToString();

Now you can execute and check.

No comments:

Post a Comment