1. 程式人生 > >Web.config 可配置的數據

Web.config 可配置的數據

技術 顯示 errors auth 條件 bug pass 默認 錯誤

1.compilation:用來配置 ASP.NET 要編譯 Web 應用程序。

技術分享
1 <compilation debug="true"          //是否調試
2     optimizeCompilations="true"    //是否重新編譯   默認false
3     targetFramework="4.0" />       // 指定.NET Framework版本 
View Code

2.自定義錯誤

model : 指定是啟用還是禁用自定義錯誤 ,mode="On|Off|RemoteOnly" 啟用|禁用|默認值。

技術分享
<customErrors mode="
RemoteOnly" //是否啟用和禁用 defaultRedirect="GenericErrorPage.htm"> //出錯時將瀏覽器定向到的默認 URL <error statusCode="403" redirect="NoAccess.htm" />//403錯誤顯示頁面 <error statusCode="404" redirect="FileNotFound.htm" />//404錯誤顯示頁面 </customErrors>
View Code

3.身份驗證和角色

mode:指定應用程序的默認身份驗證模式。  mode="[Windows|Forms|Passport|None]"   window身份驗證|窗體身份驗證|默認身份驗證|無需身份驗證
技術分享
<authentication mode="Windows"/>
View Code

4.system.webServer 只適用於 IIS 7.0 集成模式,而不適用於經典模式。具體而言,如果應用程序正在經典模式下運行,則會忽略 Web.config 文件的 system.WebServer 節中指定的所有托管代碼模塊和處理程序。與 IIS 的早期版本相同,托管代碼模塊和處理程序必須在 system.web 節的 httpModules 和 httpHandlers 元素中定義。

system.webServer 節的三個常見配置任務:

1) 添加默認文件,以便在請求 URL 未包含特定的文件時,提供該默認文件。

技術分享
<configuration>
  <system.webServer>
    <defaultDocument>
       <files>
           <add value="Products.aspx" /> 
        </files>   
     </defaultDocument>
  </system.webServer>
</configuration>                 
View Code

  2) 註冊托管代碼:每次請求時都會調用托管代碼模塊,通過該模塊可對請求或響應進行自定義。

技術分享
<configuration>
  <system.webServer>
    <modules>
      <add name="CustomModule" type="Samples.CustomModule" 
           precondition="managedHandler" />
    </modules>
//此前置條件會導致僅在請求 ASP.NET 應用程序資源(例如 .aspx 文件或托管處理程序)時才調用該模塊。該資源中不包括靜態文件(例如 .htm 文件)。
    <defaultDocument>
      <files>
        <add value="Products.aspx" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>
View Code

  3) 配置自定義響應標頭

技術分享
//實際的名稱和類型將取決於該標頭在應用程序中的功能。下面的示例演示如何添加名為 CustomHeader 且值為 CustomHeader 的自定義標頭。
<configuration>
  <system.webServer>
    <httpProtocol>      <customHeaders>        <add name="CustomHeader" value="CustomHeader" />      <customHeaders>    </httpProtocol>
  </system.webServer>
</configuration>
View Code

Web.config 可配置的數據