如何获取每个视图的页面查看总数

如何获取每个视图的页面查看总数

本文介绍了如何获取每个视图的页面查看总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,

我在Global.asax.cs中有这个:



Hello Guys,
I have this in my Global.asax.cs:

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





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





我的观点中有这个:



I have this in my view:

<p>Total Number of visitors: @ApplicationInstance.Application["Totaluser"]</p>









我在启动应用程序时一直收到空引用异常。



我需要帮助



我尝试了什么:







I keep getting a null reference exception when starting my app.

Plese I need help on that

What I have tried:

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





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

推荐答案

<p>Total Number of visitors: @ApplicationInstance.Application["Totaluser"]</p>





应该是





Should be

<p>Total Number of visitors: @ApplicationInstance.Application["NoOfVisitors"]</p>





请尝试使用此功能改变。

谢谢



Please try with this change.
Thanks


这篇关于如何获取每个视图的页面查看总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 05:44