How to count website visitors in asp.net c#
Many times our client wants that how many visitors
visited his web site. In this article I have taken global.asax .Below explain:-
global.asax :-.
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["countnumberofuser"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is
started
Application.Lock();
Application["countnumberofuser"] = (int)Application["countnumberofuser"] + 1;
Application.UnLock();
}
</script>
Source Code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="countnumberofvisitor.aspx.cs" Inherits="countnumberofvisitor" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Visitor:-
<asp:Label ID="countnumberofuser" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Code Behind(C#):-
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public partial class countnumberofvisitor : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
countnumberofuser.Text = Application["countnumberofuser"].ToString();
}
}
Out-Put:-
How to count website visitors in asp.net c#
Reviewed by NEERAJ SRIVASTAVA
on
10:39:00 PM
Rating:
No comments: