Header Ads Widget

ASP.NET pr-14 || Create a web application using Global.asax file which will count the number of visitors on web page.

Practical-15

 _ASP.NET


 Practical-14 
Create a web application using Global.asax file which will count the number of visitors on web page.
 

OnlineVisitorCntPage.aspx:-

<%@ Page Language="vb" AutoEventWireup="false"CodeBehind="OnlineVisitorCntPage.aspx.vb"

Inherits="GlobalPract.OnlineVisitorCntPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

 <title></title>

</head>

<body>

 <form id="form1" runat="server">

 <div>

 </div>

 </form>

</body>

</html>

 

 

OnlineVisitorCntPage.aspx.vb:-

Public Class OnlineVisitorCntPage

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Session.Timeout = 1

        Response.Write("Online :" & Application.Item("oCnt"))

        Response.Write("Visitors :" & Application.Item("vCnt"))

    End Sub

End Class

 

 

Web.config:-

Imports System.Web.SessionState

Public Class Global_asax

    Inherits System.Web.HttpApplication

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

        ' Fires when the application is started

        Application.Item("vCnt") = 0

        Application.Item("oCnt") = 0

    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)

        ' Fires when the session is started

        Application.Item("vCnt") =

       Convert.ToInt16(Application.Item("vCnt")) + 1

        Application.Item("oCnt") =

       Convert.ToInt16(Application.Item("oCnt")) + 1

    End Sub

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)

        ' Fires at the beginning of each request

    End Sub

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal ByValue As EventArgs)

        ' Fires upon attempting to authenticate the use

    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

        ' Fires when an error occurs

    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)

        ' Fires when the session ends

        Application.Item("oCnt") =

       Convert.ToInt16(Application.Item("oCnt")) - 1

    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)

        ' Fires when the application ends

    End Sub

End Class

 

 

Output Screenshot:-










Post a Comment

0 Comments