熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET入門教程 11.6.2 存儲首選項[2]

2022-06-13   來源: .NET編程 

    ()右擊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>

 

    ()再次運行該頁面您將看到現在頁面上有一個下拉列表框(顯示在圖的底部)用於允許選擇不同的主題以存儲在用戶配置文件中

[]  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15605.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.