ASP.NET HTTP模組和處理常式(5)

來源:互聯網
上載者:User
在設定檔中註冊HTTP模組
  
    當我們建立了HTTP模組並把它複製到Web應用程式的bin目錄或者全域組件緩衝(Global Assembly Cache)之後,接下來就應該在web.config或machine.config中註冊它了。
  
    我們可以使用<httpModules>和<add>節點把HTTP模組添加到Web應用程式中。實際上模組都使用<add>節點列舉在<httpModules>和</httpModules>節點之內了。
  
    因為配置設定資訊是可以繼承的,所以子目錄從父目錄那兒繼承配置設定資訊。其結果是,子目錄可能繼承了一些不需要的HTTP模組(它們是父配置資訊的一部分);因此,我們需要一種刪除這些不需要的模組的方法。我們可以使用<remove>節點;如果我們希望刪除從應用程式繼承得到的所有HTTP模組,可以使用<clear>節點。
  
    下面的代碼是添加HTTP模組的一個通用樣本:
  
  <httpModules>
  <add type="classname, assemblyname" name="modulename" />
  <httpModules>
  
    下面的代碼是從應用程式中刪除HTTP模組的一個通用樣本:
  
  <httpModules>
  <remove name="modulename" />
  <httpModules>
  
    在上面的XML中:
  
    · Type屬性用類和組件名稱的形式指定了HTTP模組的實際類型。
  
    · Name屬性指定了模組的易記名稱。其它應用程式可以使用這個名稱來識別HTTP模組。
  
    ASP.NET運行時如何使用HTTP模組
  
    ASP.NET運行時使用HTTP模組實現某些特殊的功能。下面的片段來自於machine.config檔案,它顯示了ASP.NET運行時安裝的HTTP模組:
  
  <httpModules>
   <add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/>
   <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
   <add name="WindowsAuthentication"
  type="System.Web.Security.WindowsAuthenticationModule"/>
   <add name="FormsAuthentication"
  type="System.Web.Security.FormsAuthenticationModule"/>
   <add name="PassportAuthentication"
  type="System.Web.Security.PassportAuthenticationModule"/>
   <add name="UrlAuthorization"
  type="System.Web.Security.UrlAuthorizationModule"/>
   <add name="FileAuthorization"
  type="System.Web.Security.FileAuthorizationModule"/>
  </httpModules> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.