()右击App_Code文件夹并且添加一个新项从可用模板的列表中选择Class并且将其称为ThemeModulevb
()在新的Class文件中添加如下代码
Imports MicrosoftVisualBasic
Imports System
Imports SystemWeb
Imports SystemWebUI
Namespace WroxWebGlobalEvents
Public Class ThemeModule
Implements IHttpModule
Public Sub Dispose() Implements SystemWebIHttpModuleDispose
End Sub
Public Sub Init(ByVal context As SystemWebHttpApplication) Implements SystemWebIHttpModuleInit
AddHandler contextPreRequestHandlerExecute New EventHandler(AddressOf app_PreRequestHandlerExecute)
End Sub
Private Sub app_PreRequestHandlerExecute(ByVal Sender As Object ByVal E As EventArgs)
HttpContextCurrentTraceWrite(ThemeModule app_PreRequestHandlerExecute)
Dim p As Page = TryCast(HttpContextCurrentHandler Page)
If p IsNot Nothing Then
Dim pb As ProfileCommon = DirectCast(HttpContextCurrentProfile ProfileCommon)
pTheme = pbTheme
End If
End Sub
End Class
End Namespace
()保存文件然后打开Webconfig并且添加如下突出显示的代码就在SystemWeb节点下
<systemweb>
<httpModules>
<add name=Page type=WroxWebGlobalEventsThemeModule/>
</httpModules>
()再次运行该页面您将看到现在页面上有一个下拉列表框(显示在图的底部)用于允许选择不同的主题以存储在用户配置文件中
[] [] [] [] [] []