c#顯示當(dāng)前在線人數(shù)示例
1、Global.asax文件:
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// 在應(yīng)用程序啟動(dòng)時(shí)運(yùn)行的代碼
//載入配置文檔
XmlDocument AppConfig = new XmlDocument();
AppConfig.Load(HttpContext.Current.Server.MapPath("~/AppConfig.xml"));
//讀取配置信息
XmlNode xnList = AppConfig.GetElementsByTagName("dblist")[0];
XmlElement xeDb1 = (XmlElement)xnList.ChildNodes[0];
XmlElement xeDb2 = (XmlElement)xnList.ChildNodes[1];
Application["db1user"] = xeDb1.GetAttribute("user");
Application["db1source"] = xeDb1.GetAttribute("source");
Application["db2user"] = xeDb2.GetAttribute("user");
Application["db2source"] = xeDb2.GetAttribute("source");
Application["count"] = 0;
}
void Application_End(object sender, EventArgs e)
{
//在應(yīng)用程序關(guān)閉時(shí)運(yùn)行的代碼
}
void Application_Error(object sender, EventArgs e)
{
//在出現(xiàn)未處理的錯(cuò)誤時(shí)運(yùn)行的代碼
}
void Session_Start(object sender, EventArgs e)
{
//在新會(huì)話啟動(dòng)時(shí)運(yùn)行的代碼
Application["count"] = Convert.ToInt32(Application["count"])+1;
}
void Session_End(object sender, EventArgs e)
{
//在會(huì)話結(jié)束時(shí)運(yùn)行的代碼。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式設(shè)置為
// InProc 時(shí),才會(huì)引發(fā) Session_End 事件。如果會(huì)話模式
//設(shè)置為 StateServer 或 SQLServer,則不會(huì)引發(fā)該事件。
Application["count"] = Convert.ToInt32(Application["count"]) - 1;
}
</script
2、顯示頁面:
前臺(tái):
<span id="Span1" runat="server" class="bottom"> </span>
后臺(tái):
Span1.InnerHtml = "當(dāng)前在線" + Application["count"].ToString() + "人";
- 不用Global.asa也能實(shí)現(xiàn)統(tǒng)計(jì)在線人數(shù)嗎?
- 統(tǒng)計(jì)在線人數(shù)是實(shí)時(shí)的嗎?
- 被動(dòng)式統(tǒng)計(jì)網(wǎng)站在線人數(shù)
- asp論壇在線人數(shù)統(tǒng)計(jì)研究
- 也談php網(wǎng)站在線人數(shù)統(tǒng)計(jì)
- javascript 傳統(tǒng)事件模型構(gòu)造的事件監(jiān)聽器實(shí)現(xiàn)代碼
- 封裝了一個(gè)支持匿名函數(shù)的Javascript事件監(jiān)聽器
- php+memcache實(shí)現(xiàn)的網(wǎng)站在線人數(shù)統(tǒng)計(jì)代碼
- PHP+jquery實(shí)時(shí)顯示網(wǎng)站在線人數(shù)的方法
- jsp利用application統(tǒng)計(jì)在線人數(shù)的方法
- php實(shí)現(xiàn)統(tǒng)計(jì)網(wǎng)站在線人數(shù)的方法
- ASP.NET中使用Application對(duì)象實(shí)現(xiàn)簡單在線人數(shù)統(tǒng)計(jì)功能
- php使用Session和文件統(tǒng)計(jì)在線人數(shù)
- 淺析JAVA中過濾器、監(jiān)聽器、攔截器的區(qū)別
- 利用java監(jiān)聽器實(shí)現(xiàn)在線人數(shù)統(tǒng)計(jì)
相關(guān)文章
C# winform實(shí)現(xiàn)自動(dòng)更新
這篇文章主要為大家詳細(xì)介紹了C# winform實(shí)現(xiàn)自動(dòng)更新的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-10-10
C#使用Socket實(shí)現(xiàn)局域網(wǎng)聊天
這篇文章主要為大家詳細(xì)介紹了C#使用Socket實(shí)現(xiàn)局域網(wǎng)聊天的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
c#將list類型轉(zhuǎn)換成DataTable方法示例
將List類型轉(zhuǎn)換成DataTable的通用方法,大家參考使用吧2013-12-12
C#使用SQLite進(jìn)行大數(shù)據(jù)量高效處理的代碼示例
在軟件開發(fā)中,高效處理大數(shù)據(jù)量是一個(gè)常見且具有挑戰(zhàn)性的任務(wù),SQLite因其零配置、嵌入式、跨平臺(tái)的特性,成為許多開發(fā)者的首選數(shù)據(jù)庫,本文將深入探討如何使用SQLite優(yōu)化大數(shù)據(jù)量的存儲(chǔ)和檢索,,需要的朋友可以參考下2025-04-04

