如果不满足某些条件,我正在开发一个 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 是设置我的事件处理程序的正确事件吗?