特定の基準が満たされない場合に、Web サイトの特定のコンテンツを非表示にする httpmodule に取り組んでいます。私のハンドラーのセットアップは非常に簡単です。私の質問に関連する部分は次のとおりです。
Public Interface IFeatureItem
Property ID As Guid
Sub FeatureItemPreRenderComplete(ByVal sender As Object, ByVal e As EventArgs)
End Interface
Public Class MyModule
Implements System.Web.IHttpModule
Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
AddHandler context.PreRequestHandlerExecute, AddressOf Application_PreRequestHandlerExecute
End Sub
Private Sub Application_PreRequestHandlerExecute(ByVal source As Object, ByVal e As EventArgs)
If TypeOf source Is HttpApplication Then
Dim Application As HttpApplication = source
If TypeOf Application.Context.Handler Is Page Then
Dim Page As Page = Application.Context.Handler
AddHandler Page.PreRenderComplete, AddressOf FeatureItemPreRenderComplete
ElseIf TypeOf Application.Context.Handler Is System.Web.Mvc.MvcHandler Then
Dim MvcHandler As System.Web.Mvc.MvcHandler = Application.Context.Handler
<What do I do here>
End If
End If
End Sub
Private Sub FeatureItemPreRenderComplete(ByVal source As Object, ByVal e As System.EventArgs)
Dim Page As Page = source
Dim Repository As IFeatureRepository = GetRepository(Page.Application) 'Holds supported IFeature
Dim IFeatureItems As IEnumerable(Of IFeatureItem) = GetIFeatureItems(Page) 'Goes through Page's control tree and returns IFeatureItems
For Each IFeatureItem In IFeatureItems
Dim FeatureEventArgs As FeatureEventArgs = New FeatureEventArgs(IFeatureItem.ID, FeatureAllowed(IFeatureItem.ID, Repository))
IFeatureItem.FeatureItemPreRenderComplete(Me, FeatureEventArgs)
Next
End Sub
<Irrelevant stuff removed>
End Class
ハンドラーがページの場合、基本的にページ オブジェクトにイベント ハンドラーを設定します。次に、PreRenderEvent でページ上のすべての IFeatureItem をループし、IFeatureItem のメソッドを呼び出します。ハンドラーがページの場合、これはうまく機能します。
このサイトには、ダッシュボードの mvc ビューがあり、IFeatureItem である可能性のある Web フォーム コントロールも含まれています。私がやりたいことは、このビューで webforms コントロールをループして、通常のページと同じ処理を行うことですが、その方法がわかりません。これはモジュール内で可能ですか? PreRequestHandlerExecute は、イベント ハンドラーを設定するための適切なイベントですか?