Introduction
This article will explain the code to get the total visitors count of Asp.Net MVC website using Application variable.
Step 1
- Create an Asp.Net MVC website and write the below code in Global.asax file.
- In Application_Start() method declare the variable like below code.
- Application["Totaluser"] = 0;
- Write the session_Start() method like below:
- protected void Session_Start()
- {
- Application.Lock();
- Application["Totaluser"] = (int)Application["Totaluser"] + 1;
- Application.UnLock();
- }
If you want to show the total visitors count on all the pages then use Layout.cshtml or the page/view where you want to show the total count put the below code.
<p>Total Number of visitors: @ApplicationInstance.Application["Totaluser"]</p>
mohan GCRSPosted Nov 14, 2019, 6:56 AM
Can u provide an same article for MVC plaftform
mohan GCRSPosted Nov 14, 2019, 6:53 AM
No of vissits is not working untill we must keep <sessionState mode="InProc" cookieless="true" timeout="30"></sessionState> inside <system web> in webconfig then it is working good but small bug is there that is sessionid is displaying in URL like http://localhost:533/(S(m0iehgqlodmgpbsmoj41j02r))/Home/Index. how to remove the session id ina url please tell me... please share the information to my mail [email protected]
mohan GCRSPosted Nov 14, 2019, 6:43 AM
...<sessionState mode="InProc" cookieless="true" timeout="30"></sessionState> inside <system web> in webconfig its working nicely but small bug sessionid is showing in URL http://localhost:533/(S(m0iehgqlodmgpbsmoj41j02r))/Home/Index please tell me how to solve
mohan GCRSPosted Nov 14, 2019, 6:43 AM
This article is very good, i had solve the problem of no of visits, but i had a small bug please tell me how to solve it <sessionState mode="InProc" cookieless="true" timeout="30"></sessionState> inside <system web> in webconfig its working nicely but small bug sessionid is showing in URL http://localhost:533/(S(m0iehgqlodmgpbsmoj41j02r))/Home/Index please tell me how to solve
صبري محمدPosted Aug 7, 2017, 8:07 AM
How save this in database ?
patel saurabhPosted Jan 17, 2017, 1:42 AM
I have one problem in above code.when i restart application counting start with zero.
fadoua jaouharPosted Feb 2, 2015, 4:54 PM
Thanks for this article very helpful ^__^ .