Создание счетчика посещений в ASP. net с использованием global.aspx - PullRequest
0 голосов
/ 08 апреля 2020

Эй, ребята, вы можете мне помочь с этим ???? я создаю счетчик посещений для моего практического файла, мой код успешно работает, но счетчик не увеличивается, он застрял на 1. Я смотрел видео, но они показывают с использованием базы данных, но я должен сделать это с помощью файла global.aspx, пожалуйста, помогите мне с этим код вот мой код ...

Practical21.aspx

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Practical21.aspx.cs" Inherits="Practical21.Practical21" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h3>
                No. of Visiters:&nbsp;&nbsp;
                <asp:Label ID="lblCount" runat="server" Text="Label"></asp:Label>
            </h3>
        </div>
    </form>
</body>
</html>

Practical21.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Practical21
{
    public partial class Practical21 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Application["User"] != null)
            {
                lblCount.Text = Application["User"].ToString();
            }
        }
    }
}

Global.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;

namespace Practical21
{
    public class Global : System.Web.HttpApplication
    {
        int nouser;
        protected void Application_Start(object sender, EventArgs e)
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            nouser = 0;
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            if (Application["User"] != null)
            {
                nouser = nouser + 1;
                Application["User"] = nouser;
            }
            else
            {
                nouser = Convert.ToInt32(Application["User"]);
                nouser = nouser + 1;
                Application["User"] = nouser;
            }
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}

1-й прогон 2-й прогон

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...