当前用户数 [英] number of current user

查看:78
本文介绍了当前用户数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关闭浏览器后,如何减去当前用户数.我在google上chkd,但它说没有为此的事件处理程序...我该怎么办.请帮助....

How can i subtract the number of current users as soon as i close the browser. I chkd on google but it says that there is no event handler for that...What should i do. Please Help....

推荐答案

您可以使用Session_Start来增加用户数和
Session_End事件,用于减少ASP.net中Global.asax(Global.asax.vb)文件中的用户数

如果您的项目中没有此文件,则可以使用添加新项-全局应用程序类"添加它.
这是您的Global.asax.vb文件的示例事件

You Can Use Session_Start to Increase number of users and
Session_End Event to decrease the number of user in Global.asax (Global.asax.vb) file in ASP.net

If you don''t have this file in your project you can add it using Add New Item - Global Application Class

Here is sample Event for your Global.asax.vb file

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
       ' Code that runs when a new session is started
   End Sub

   Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
       ' Code that runs when a session ends.
       ' Note: The Session_End event is raised only when the sessionstate mode
       ' is set to InProc in the Web.config file. If session mode is set to StateServer
       ' or SQLServer, the event is not raised.
   End Sub


您在这里

如何显示在线数ASP.NET网站的用户/访客? [
Here you go

How to show number of online users / visitors for ASP.NET website?[^]


简短的回答是没有可靠的方法.会话在服务器端而不是客户端(浏览器)端进行处理.

一种不可靠的方法是处理javascript中的onunload事件,然后回发Ajax调用,该调用将通知服务器浏览器正在关闭.如果未启用javascript,网络问题或浏览器在有机会发送请求之前被杀死,则此方法将无效.

纠正的做法是问自己:您要达到什么目标?
The short answer is there is no reliable way. Sessions are handled server side, not client (browser) side.

An unreliable method is to handle the onunload event in javascript and fire back an Ajax call that would inform the server that the browser is closing. This won''t work if javascript isn''t enabled, if there is a network problem, or if the browser is killed before it gets a chance to send the request.

The correc thing to do is ask yourself: what are you trying to achieve?


这篇关于当前用户数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆