📄 whosonmodule.cs
字号:
using System;
using System.Web;
using System.Collections;
using System.Configuration;
namespace WhosOn {
public class WhosOnModule : IHttpModule {
void IHttpModule.Init(HttpApplication myApp) {
myApp.BeginRequest += new EventHandler(this.OnEnter);
}
void IHttpModule.Dispose() {
}
public void OnEnter(object s, EventArgs e) {
HttpApplication objApp;
HttpContext objContext;
String strPath;
Queue colPageStats;
StatsEntry objStatsEntry;
int intMaxEntries;
objApp = (HttpApplication)s;
objContext = objApp.Context;
strPath = objContext.Request.Path.ToLower();
// Don't keep stats on .axd pages
if (strPath.Substring(strPath.Length-4, 4 ) == ".axd")
return;
strPath = strPath.Substring( 0, strPath.LastIndexOf(".") - 1 );
// Get Max Entries From Web.Config
intMaxEntries = Convert.ToInt32(ConfigurationSettings.AppSettings["whoson"]);
// Check whether Cache object exists
colPageStats = (Queue)objContext.Cache["whoson_" + strPath];
if (colPageStats == null)
colPageStats = new Queue();
// Add Current Request to the Queue
objStatsEntry = new StatsEntry(
objContext.Timestamp,
objContext.Request.Browser.Type,
objContext.Request.UserHostName,
objContext.Request.ServerVariables["HTTP_REFERER"]
);
colPageStats.Enqueue( objStatsEntry );
// Delete Previous Entries
if (intMaxEntries > 0) {
while (colPageStats.Count > intMaxEntries) {
colPageStats.Dequeue();
}
}
// Update the Cache
objContext.Cache["whoson_" + strPath] = colPageStats;
}
}
public class StatsEntry {
public DateTime TimeStamp;
public string BrowserType;
public string UserHostName;
public string Referrer;
public StatsEntry(DateTime TimeStamp, string BrowserType, string userHostName, string Referrer) {
this.TimeStamp = TimeStamp;
this.BrowserType = BrowserType;
this.UserHostName = UserHostName;
this.Referrer = Referrer;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -