⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 whosonmodule.vb

📁 asp.net技术内幕的书配源码
💻 VB
字号:
Imports System
Imports System.Web
Imports System.Collections
Imports System.Configuration
Imports Microsoft.VisualBasic

Namespace WhosOn

Public Class WhosOnModule 
Implements IHttpModule

Public Sub Init( ByVal myApp As HttpApplication ) _
Implements IHttpModule.Init
  AddHandler myApp.BeginRequest, AddressOf Me.OnEnter
End Sub

Public Sub Dispose() _
Implements IHttpModule.Dispose
End Sub

Public Sub OnEnter( s As Object, e As EventArgs )
  Dim objApp As HttpApplication
  Dim objContext As HttpContext
  Dim strPath As String
  Dim colPageStats As Queue
  Dim objStatsEntry As StatsEntry
  Dim intMaxEntries As Integer

  objApp = CType( s, HttpApplication )
  objContext = objApp.Context
  strPath = objContext.Request.Path.ToLower()

  ' Don't keep stats on .axd pages
  If Right( strPath, 4 ) = ".axd" Then
    Exit Sub
  End If 
  strPath = strPath.SubString( 0, InstrRev( strPath, "." ) - 1 )

  ' Get Max Entries From Web.Config
  intMaxEntries = cINT( ConfigurationSettings.AppSettings( "whoson" ) )

  ' Check whether Cache object exists
  colPageStats = CType( objContext.Cache( "whoson_" & strPath ), Queue )
  If colPageStats Is Nothing Then
    colPageStats = New Queue()
  End If

  ' 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 <> Nothing Then
  While colPageStats.Count > intMaxEntries
    colPageStats.Dequeue()
  End While
  End If

  ' Update the Cache
  objContext.Cache( "whoson_" & strPath ) = colPageStats
End Sub

End Class

Public Class StatsEntry

Public TimeStamp As DateTime
Public BrowserType As String
Public UserHostName As String
Public Referrer As String

Public Sub New( _
  TimeStamp As DateTime, _
  BrowserType As String, _
  UserHostName As String, _
  Referrer As String )
  
  Me.TimeStamp = TimeStamp
  Me.BrowserType = BrowserType
  Me.UserHostName = UserHostName
  Me.Referrer = Referrer
End Sub

End Class


End Namespace

  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -