A: 

Hi,

I have implemented something similar to this as a base page class for my aspx pages, but as you mentioned a module would work as well. In my opinion, if this functionality is needed across all pages I would just crate a base class only because maintaining another http-module is more of a pain because it needs to be mapped in your web config / iis. Url rewriting is cpu intensive and may not provide you the flexibility you need - again it just adds another configuration / iss dependency. I don't think either of these are going to incur much overhead as long as you implement some sort of caching.

Hope this helps...

Enjoy!

Doug
+1  A: 

This is a classic case where a HTTP module makes the most sense--you wish to dive into the URL handling on all requests. Perf-overhead-wise you shouldn't have that much of an issue presuming you can short-circuit things correctly and avoid doing DB/cache lookups where you don't need.

Configuration-wise, you should already have to solve the problem of deploying and managing your configuration, so I doubt if another custom module adds much overhead.

Code-wise, its generally better to favor composition over inheritance--you can add or remove the module as required--but having code statically included into a bloated base page class can create more challenges.

Wyatt Barnett
A: 

I usually create a Singleton class to hold the site's request context, and store it in the HttpContext.Current.Items(). I initialize this class in the Application_BeginRequest routine.

Imports System.Web

Public Class SiteContext

Private _viewId As Int32 
Private _tab As String
Private _action As String

Private Sub New()
    _viewId = -1
    _tab = String.Empty
    _action = String.Empty

    FillContext()
End Sub

Public Shared Function Instance() As SiteContext
' gets the site specific context for the current request

    If HttpContext.Current.Items("RequestContext") Is Nothing Then
        HttpContext.Current.Items("RequestContext") = New SiteContext
    End If
    Return HttpContext.Current.Items("RequestContext")

End Function

' fill the request context with site specific items
Private Sub FillContext()

    ' iterate through all items passes via the querystring and save values to matching key property names
    For i As Int16 = 0 To _context.Request.QueryString.Count - 1
        Dim qryItem As String = _context.Request.QueryString.Keys.Item(i)

        Select Case qryItem
            Case "v", "view", "viewid", "vid" ' VIEW ID
                If IsNumeric(_context.Request.QueryString(qryItem)) AndAlso CType(_context.Request.QueryString(qryItem), Double) < 10000 Then
                    _viewId = CType(_context.Request.QueryString(qryItem), Int32)
                End If

            Case "tab" ' TAB ID; secondary parameter to choose sub view
                _tab = _context.Request.QueryString(qryItem)

            Case "action" ' ACTION ID; tertiary parameter to choose sub-sub view
                _action = _context.Request.QueryString(qryItem)

            Case Else

        End Select
    Next

End Sub

Public Property ViewId() As Int32
    Get
        Return _viewId
    End Get
    Set(ByVal Value As Int32)
        If Value < 1 Then
            Value = 1
        End If
        _viewId = Value
    End Set
End Property

Public Property Tab() As String
    Get
        Return _tab
    End Get
    Set(ByVal Value As String)
        _tab = Value.Trim
    End Set
End Property

Public Property Action() As String
    Get
        Return _action
    End Get
    Set(ByVal Value As String)
        _action = Value.Trim
    End Set
End Property

End Class