ASP.NET中的配置文件

ASP.NET中的配置文件

原創 2014年10月13日 08:15:27
 

在機房收費系統的時候曾經應用過配置文件,當時也就那麼一用對配置文件瞭解的不是很透徹,下面就來總結一下有關配置文件的一些操做。html

 

什麼是配置文件java

 

說白了就是用來保存項目中的一些配置信息,尤爲是之後須要變動的配置信息。好比說鏈接數據庫的操做,變動時,直接修改便可。ASP.NET網站IIS啓動的時候會加載配置文件中的配置信息,而後進行緩存這些信息,在運行過程當中會監視配置文件信息的變化狀況,一旦發生變化會從新讀取並緩存。web

 

爲何要使用配置文件?ajax

 

這就涉及到ASP.NET的運行機制了。sql

 

                   ASP.NET——DLL文件——JIT加工——本地機器代碼——緩存數據庫

 

以上的過程就是ASP.NET頁面在第一次請求的時候會被編譯成DLL。文件,由JIT編程成本地代碼執行,並將本地機器代碼緩存。所以ASPX頁面第一次打開的時候,會比較慢,之後執行的時候直接調用緩存便可。express

 

正是因爲這一點,.config文件逃過了這一劫,在發佈Web應用程序的時候,web.config不被編譯進去DLL文件。若是未來客戶端發生變化,直接用記事本修改web.config文件,就能夠從新運行。從這一點咱們就能夠看web.config文件保存變動配置信息的好處了。編程

 

在這裏多提一點,從上面的ASP.NET執行機制中看出,瀏覽器端只會執行機器代碼,全部的.ASPX文件多會被轉換成機器代碼,所以之後若是針對網站的性能優化的話,能儘可能用靜態網頁,如HTML等,由於會提高網站性能,減小了編譯的時間。json

 

讀取優先級(就近原則)如今當前頁面尋找目錄下的web.config文件,存在就中止c#

  1. 當前網站根目錄中查找web.config文件,存在就中止

  2. 軟件安裝路徑中查找web.config文件,存在就中止

 

 

 

 

 

 

 

 

 

 

 

 

Asp.Net 之 Web.config 配置文件詳解

 

  在asp.net中配置文件名通常默認是web.config。每一個web.config文件都是基於XML的文本文件,而且能夠保存到Web應用程序中的任何目錄中。在發佈Web應用程序時web.config文件並不編譯進dll文件中。若是未來客戶端發生了變化,僅僅須要用記事本打開web.config文件編輯相關設置就能夠從新正常使用,很是方便。

一、配置文件的查找優先級

[1]在.net提供了一個針對當前機器的配置文件,這個文件是machine.config,它位於%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\文件下(%windir%是系統分區下的系統目錄,在命令行模式下輸入%windir%而後回車就能查看當前機器的系統目錄,在Windows7及Windows10中%windir%是系統分區下的windows目錄,這個文件裏面定義了針對當前機器的WinForm程序和asp.net應用程序的配置。下面是machine.config文件的內容:
複製代碼
<?xml version="1.0" encoding="UTF-8"?>
<!--
    Please refer to machine.config.comments for a description and
    the default values of each configuration section.

    For a full documentation of the schema please refer to
    http://go.microsoft.com/fwlink/?LinkId=42127

    To improve performance, machine.config should contain only those
    settings that differ from their defaults.
-->
<configuration>
    <configSections>
        <section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false"/>
        <section name="connectionStrings" type="System.Configuration.ConnectionStringsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false"/>
        <section name="mscorlib" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowLocation="false"/>
        <section name="runtime" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowLocation="false"/>
        <section name="assemblyBinding" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowLocation="false"/>
        <section name="satelliteassemblies" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowLocation="false"/>
        <section name="startup" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowLocation="false"/>
        <section name="system.codedom" type="System.CodeDom.Compiler.CodeDomConfigurationHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="system.data" type="System.Data.Common.DbProviderFactoriesConfigurationHandler, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="system.data.dataset" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" restartOnExternalChanges="false"/>
        <section name="system.data.odbc" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="system.data.oledb" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="system.data.oracleclient" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="system.data.sqlclient" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="system.diagnostics" type="System.Diagnostics.SystemDiagnosticsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="system.runtime.remoting" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowLocation="false"/>
        <section name="system.windows.forms" type="System.Windows.Forms.WindowsFormsSection, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="windows" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowLocation="false"/>
        <sectionGroup name="system.xml.serialization" type="System.Xml.Serialization.Configuration.SerializationSectionGroup, System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="schemaImporterExtensions" type="System.Xml.Serialization.Configuration.SchemaImporterExtensionsSection, System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <section name="dateTimeSerialization" type="System.Xml.Serialization.Configuration.DateTimeSerializationSection, System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <section name="xmlSerializer" type="System.Xml.Serialization.Configuration.XmlSerializerSection, System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
        <sectionGroup name="system.net" type="System.Net.Configuration.NetSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="authenticationModules" type="System.Net.Configuration.AuthenticationModulesSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <section name="connectionManagement" type="System.Net.Configuration.ConnectionManagementSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <section name="defaultProxy" type="System.Net.Configuration.DefaultProxySection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <sectionGroup name="mailSettings" type="System.Net.Configuration.MailSettingsSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                <section name="smtp" type="System.Net.Configuration.SmtpSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            </sectionGroup>
            <section name="requestCaching" type="System.Net.Configuration.RequestCachingSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <section name="settings" type="System.Net.Configuration.SettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <section name="webRequestModules" type="System.Net.Configuration.WebRequestModulesSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        </sectionGroup>
        <sectionGroup name="system.transactions" type="System.Transactions.Configuration.TransactionsSectionGroup, System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null">
            <section name="defaultSettings" type="System.Transactions.Configuration.DefaultSettingsSection, System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null"/>
            <section name="machineSettings" type="System.Transactions.Configuration.MachineSettingsSection, System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null" allowDefinition="MachineOnly" allowExeDefinition="MachineOnly"/>
        </sectionGroup>
        <sectionGroup name="system.web" type="System.Web.Configuration.SystemWebSectionGroup, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
            <section name="anonymousIdentification" type="System.Web.Configuration.AnonymousIdentificationSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="authentication" type="System.Web.Configuration.AuthenticationSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="authorization" type="System.Web.Configuration.AuthorizationSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="browserCaps" type="System.Web.Configuration.HttpCapabilitiesSectionHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="clientTarget" type="System.Web.Configuration.ClientTargetSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="compilation" type="System.Web.Configuration.CompilationSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="customErrors" type="System.Web.Configuration.CustomErrorsSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="deployment" type="System.Web.Configuration.DeploymentSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineOnly"/>
            <section name="deviceFilters" type="System.Web.Mobile.DeviceFiltersSection, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="globalization" type="System.Web.Configuration.GlobalizationSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="healthMonitoring" type="System.Web.Configuration.HealthMonitoringSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="hostingEnvironment" type="System.Web.Configuration.HostingEnvironmentSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="httpCookies" type="System.Web.Configuration.HttpCookiesSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="httpHandlers" type="System.Web.Configuration.HttpHandlersSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="httpModules" type="System.Web.Configuration.HttpModulesSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="httpRuntime" type="System.Web.Configuration.HttpRuntimeSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="identity" type="System.Web.Configuration.IdentitySection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="machineKey" type="System.Web.Configuration.MachineKeySection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="membership" type="System.Web.Configuration.MembershipSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="mobileControls" type="System.Web.UI.MobileControls.MobileControlsSection, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="pages" type="System.Web.Configuration.PagesSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="processModel" type="System.Web.Configuration.ProcessModelSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineOnly" allowLocation="false"/>
            <section name="profile" type="System.Web.Configuration.ProfileSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="roleManager" type="System.Web.Configuration.RoleManagerSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="securityPolicy" type="System.Web.Configuration.SecurityPolicySection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="sessionPageState" type="System.Web.Configuration.SessionPageStateSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="sessionState" type="System.Web.Configuration.SessionStateSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="siteMap" type="System.Web.Configuration.SiteMapSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="trace" type="System.Web.Configuration.TraceSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="trust" type="System.Web.Configuration.TrustSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="urlMappings" type="System.Web.Configuration.UrlMappingsSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            <section name="webControls" type="System.Web.Configuration.WebControlsSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="webParts" type="System.Web.Configuration.WebPartsSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="webServices" type="System.Web.Services.Configuration.WebServicesSection, System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <section name="xhtmlConformance" type="System.Web.Configuration.XhtmlConformanceSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <sectionGroup name="caching" type="System.Web.Configuration.SystemWebCachingSectionGroup, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
                <section name="cache" type="System.Web.Configuration.CacheSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
                <section name="outputCache" type="System.Web.Configuration.OutputCacheSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
                <section name="outputCacheSettings" type="System.Web.Configuration.OutputCacheSettingsSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
                <section name="sqlCacheDependency" type="System.Web.Configuration.SqlCacheDependencySection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication"/>
            </sectionGroup>
   <section name="protocols" type="System.Web.Configuration.ProtocolsSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToWebRoot"/>
        </sectionGroup>
        <section name="system.webServer" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  <sectionGroup name="system.runtime.serialization" type="System.Runtime.Serialization.Configuration.SerializationSectionGroup, System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
   <section name="dataContractSerializer" type="System.Runtime.Serialization.Configuration.DataContractSerializerSection, System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  </sectionGroup>
  <sectionGroup name="system.serviceModel" type="System.ServiceModel.Configuration.ServiceModelSectionGroup, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
   <section name="behaviors" type="System.ServiceModel.Configuration.BehaviorsSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
   <section name="bindings" type="System.ServiceModel.Configuration.BindingsSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
   <section name="client" type="System.ServiceModel.Configuration.ClientSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
   <section name="comContracts" type="System.ServiceModel.Configuration.ComContractsSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
   <section name="commonBehaviors" type="System.ServiceModel.Configuration.CommonBehaviorsSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowDefinition="MachineOnly" allowExeDefinition="MachineOnly"/>
   <section name="diagnostics" type="System.ServiceModel.Configuration.DiagnosticSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
   <section name="extensions" type="System.ServiceModel.Configuration.ExtensionsSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
   <section name="machineSettings" type="System.ServiceModel.Configuration.MachineSettingsSection, SMDiagnostics, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowDefinition="MachineOnly" allowExeDefinition="MachineOnly"/>
   <section name="serviceHostingEnvironment" type="System.ServiceModel.Configuration.ServiceHostingEnvironmentSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
   <section name="services" type="System.ServiceModel.Configuration.ServicesSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  </sectionGroup>
  <sectionGroup name="system.serviceModel.activation" type="System.ServiceModel.Activation.Configuration.ServiceModelActivationSectionGroup, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
   <section name="diagnostics" type="System.ServiceModel.Activation.Configuration.DiagnosticSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
   <section name="net.pipe" type="System.ServiceModel.Activation.Configuration.NetPipeSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
   <section name="net.tcp" type="System.ServiceModel.Activation.Configuration.NetTcpSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  </sectionGroup>
    </configSections>
    <configProtectedData defaultProvider="RsaProtectedConfigurationProvider">
        <providers>
            <add name="RsaProtectedConfigurationProvider" type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" description="Uses RsaCryptoServiceProvider to encrypt and decrypt" keyContainerName="NetFrameworkConfigurationKey" cspProviderName="" useMachineContainer="true" useOAEP="false"/>
            <add name="DataProtectionConfigurationProvider" type="System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" description="Uses CryptProtectData and CryptUnProtectData Windows APIs to encrypt and decrypt" useMachineProtection="true" keyEntropy=""/>
        </providers>
    </configProtectedData>
    <runtime/>
    <connectionStrings>
        <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <system.data>
        <DbProviderFactories>
            <add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/><add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/></DbProviderFactories>
    </system.data>
    <system.web>
        <processModel autoConfig="true"/>
        <httpHandlers/>
        <membership>
            <providers>
                <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
            </providers>
        </membership>
        <profile>
            <providers>
                <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            </providers>
        </profile>
        <roleManager>
            <providers>
                <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            </providers>
        </roleManager>
    </system.web>
    <system.serviceModel>
        <extensions>
            <behaviorExtensions>
                <add name="persistenceProvider" type="System.ServiceModel.Configuration.PersistenceProviderElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add name="workflowRuntime" type="System.ServiceModel.Configuration.WorkflowRuntimeElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add name="enableWebScript" type="System.ServiceModel.Configuration.WebScriptEnablingElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add name="webHttp" type="System.ServiceModel.Configuration.WebHttpElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add name="Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior" type="Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior, Microsoft.VisualStudio.Diagnostics.ServiceModelSink, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/></behaviorExtensions>
            <bindingElementExtensions>
                <add name="webMessageEncoding" type="System.ServiceModel.Configuration.WebMessageEncodingElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add name="context" type="System.ServiceModel.Configuration.ContextBindingElementExtensionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            </bindingElementExtensions>
            <bindingExtensions>
                <add name="wsHttpContextBinding" type="System.ServiceModel.Configuration.WSHttpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add name="netTcpContextBinding" type="System.ServiceModel.Configuration.NetTcpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add name="webHttpBinding" type="System.ServiceModel.Configuration.WebHttpBindingCollectionElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add name="basicHttpContextBinding" type="System.ServiceModel.Configuration.BasicHttpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            </bindingExtensions>
        </extensions>
        <client>
            <metadata>
                <policyImporters>
                    <extension type="System.ServiceModel.Channels.ContextBindingElementImporter, system.workflowservices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
                </policyImporters>
                <wsdlImporters>
                    <extension type="System.ServiceModel.Channels.ContextBindingElementImporter, system.workflowservices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
                </wsdlImporters>
            </metadata>
        </client>
        <commonBehaviors><endpointBehaviors><Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior/></endpointBehaviors><serviceBehaviors><Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior/></serviceBehaviors></commonBehaviors></system.serviceModel>
</configuration>
複製代碼

[2]在這個文件夾下還有一個web.config文件,這個文件包含了asp.net網站的經常使用配置。下面是這個web.config文件的內容:

複製代碼
<?xml version="1.0" encoding="utf-8"?><!-- the root web configuration file --><configuration>
    <!--
        Using a location directive with a missing path attribute
        scopes the configuration to the entire machine.  If used in
        conjunction with allowOverride="false", it can be used to
        prevent configuration from being altered on the machine

        Administrators that want to restrict permissions granted to
        web applications should change the default Trust level and ensure
        that overrides are not allowed
    -->
    <location allowOverride="true">
        <system.web>
            <securityPolicy>
                <trustLevel name="Full" policyFile="internal"/>
                <trustLevel name="High" policyFile="web_hightrust.config"/>
                <trustLevel name="Medium" policyFile="web_mediumtrust.config"/>
                <trustLevel name="Low" policyFile="web_lowtrust.config"/>
                <trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
            </securityPolicy>
            <trust level="Full" originUrl=""/>
        </system.web>
    </location>

    <system.net>
        <defaultProxy>
            <proxy usesystemdefault="true"/>
        </defaultProxy>
    </system.net>

    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>

        <browserCaps userAgentCacheKeyLength="64">
            <result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </browserCaps>

        <clientTarget>
            <add alias="ie5" userAgent="Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)"/>
            <add alias="ie4" userAgent="Mozilla/4.0 (compatible; MSIE 4.0; Windows NT 4.0)"/>
            <add alias="uplevel" userAgent="Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)"/>
            <add alias="downlevel" userAgent="Generic Downlevel"/>
        </clientTarget>

        <compilation>
            <assemblies>
                <add assembly="mscorlib"/>
                <add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                <add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <add assembly="System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                <add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                <add assembly="System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                <add assembly="System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                <add assembly="*"/>
              <add assembly="System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add assembly="System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add assembly="System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
                <add assembly="System.IdentityModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
                <add assembly="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
            <buildProviders>
                <add extension=".aspx" type="System.Web.Compilation.PageBuildProvider"/>
                <add extension=".ascx" type="System.Web.Compilation.UserControlBuildProvider"/>
                <add extension=".master" type="System.Web.Compilation.MasterPageBuildProvider"/>
                <add extension=".asmx" type="System.Web.Compilation.WebServiceBuildProvider"/>
                <add extension=".ashx" type="System.Web.Compilation.WebHandlerBuildProvider"/>
                <add extension=".soap" type="System.Web.Compilation.WebServiceBuildProvider"/>
                <add extension=".resx" type="System.Web.Compilation.ResXBuildProvider"/>
                <add extension=".resources" type="System.Web.Compilation.ResourcesBuildProvider"/>
                <add extension=".wsdl" type="System.Web.Compilation.WsdlBuildProvider"/>
                <add extension=".xsd" type="System.Web.Compilation.XsdBuildProvider"/>
                <add extension=".js" type="System.Web.Compilation.ForceCopyBuildProvider"/>
                <add extension=".lic" type="System.Web.Compilation.IgnoreFileBuildProvider"/>
                <add extension=".licx" type="System.Web.Compilation.IgnoreFileBuildProvider"/>
                <add extension=".exclude" type="System.Web.Compilation.IgnoreFileBuildProvider"/>
                <add extension=".refresh" type="System.Web.Compilation.IgnoreFileBuildProvider"/>
              <add extension=".xoml" type="System.ServiceModel.Activation.WorkflowServiceBuildProvider, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add extension=".svc" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </buildProviders>
            <expressionBuilders>
                <add expressionPrefix="Resources" type="System.Web.Compilation.ResourceExpressionBuilder"/>
                <add expressionPrefix="ConnectionStrings" type="System.Web.Compilation.ConnectionStringsExpressionBuilder"/>
                <add expressionPrefix="AppSettings" type="System.Web.Compilation.AppSettingsExpressionBuilder"/>
            </expressionBuilders>
        </compilation>

        <healthMonitoring>
            <bufferModes>
                <add name="Critical Notification" maxBufferSize="100" maxFlushSize="20" urgentFlushThreshold="1" regularFlushInterval="Infinite" urgentFlushInterval="00:01:00" maxBufferThreads="1"/>
                <add name="Notification" maxBufferSize="300" maxFlushSize="20" urgentFlushThreshold="1" regularFlushInterval="Infinite" urgentFlushInterval="00:01:00" maxBufferThreads="1"/>
                <add name="Analysis" maxBufferSize="1000" maxFlushSize="100" urgentFlushThreshold="100" regularFlushInterval="00:05:00" urgentFlushInterval="00:01:00" maxBufferThreads="1"/>
                <add name="Logging" maxBufferSize="1000" maxFlushSize="200" urgentFlushThreshold="800" regularFlushInterval="00:30:00" urgentFlushInterval="00:05:00" maxBufferThreads="1"/>
            </bufferModes>

            <providers>
                <add name="EventLogProvider" type="System.Web.Management.EventLogWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/>
                <add connectionStringName="LocalSqlServer" maxEventDetailsLength="1073741823" buffer="false" bufferMode="Notification" name="SqlWebEventProvider" type="System.Web.Management.SqlWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/>
                <add name="WmiWebEventProvider" type="System.Web.Management.WmiWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/>
            </providers>

            <profiles>
                <add name="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom=""/>
                <add name="Critical" minInstances="1" maxLimit="Infinite" minInterval="00:00:00" custom=""/>
            </profiles>

            <rules>
                <add name="All Errors Default" eventName="All Errors" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom=""/>
                <add name="Failure Audits Default" eventName="Failure Audits" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom=""/>
            </rules>

            <eventMappings>
                <add name="All Events" type="System.Web.Management.WebBaseEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
                <add name="Heartbeats" type="System.Web.Management.WebHeartbeatEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
                <add name="Application Lifetime Events" type="System.Web.Management.WebApplicationLifetimeEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
                <add name="Request Processing Events" type="System.Web.Management.WebRequestEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
                <add name="All Errors" type="System.Web.Management.WebBaseErrorEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
                <add name="Infrastructure Errors" type="System.Web.Management.WebErrorEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
                <add name="Request Processing Errors" type="System.Web.Management.WebRequestErrorEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
                <add name="All Audits" type="System.Web.Management.WebAuditEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
                <add name="Failure Audits" type="System.Web.Management.WebFailureAuditEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
                <add name="Success Audits" type="System.Web.Management.WebSuccessAuditEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
            </eventMappings>

        </healthMonitoring>

        <httpHandlers>
      <add path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false" />
      <add verb="*" path="*.rules" type="System.Web.HttpForbiddenHandler" validate="true"/>
      <add verb="*" path="*.xoml" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/>
            <add path="trace.axd" verb="*" type="System.Web.Handlers.TraceHandler" validate="True"/>
            <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True"/>
            <add path="*.axd" verb="*" type="System.Web.HttpNotFoundHandler" validate="True"/>
            <add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True"/>
            <add path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" validate="True"/>
            <add path="*.asmx" verb="*" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="False"/>
            <add path="*.rem" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="False"/>
            <add path="*.soap" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="False"/>
            <add path="*.asax" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.ascx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.master" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.skin" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.browser" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.sitemap" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.dll.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="True"/>
            <add path="*.exe.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="True"/>
            <add path="*.config" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.cs" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.csproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.vb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.vbproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.webinfo" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.licx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.resx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.resources" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.mdb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.vjsproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.java" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.jsl" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.ldb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.ad" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.dd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.ldd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.sd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.cd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.adprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.lddprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.sdm" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.sdmDocument" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.mdf" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.ldf" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.exclude" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*.refresh" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>
            <add path="*" verb="GET,HEAD,POST" type="System.Web.DefaultHttpHandler" validate="True"/>
            <add path="*" verb="*" type="System.Web.HttpMethodNotAllowedHandler" validate="True"/>
        </httpHandlers>

        <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="RoleManager" type="System.Web.Security.RoleManagerModule"/>
            <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/>
            <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/>
            <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule"/>
            <add name="Profile" type="System.Web.Profile.ProfileModule"/>
            <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        </httpModules>

        <mobileControls sessionStateHistorySize="6" cookielessDataDictionaryType="System.Web.Mobile.CookielessData">
            <device name="XhtmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlPageAdapter">

                <control name="System.Web.UI.MobileControls.Panel" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlPanelAdapter"/>
                <control name="System.Web.UI.MobileControls.Form" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlFormAdapter"/>
                <control name="System.Web.UI.MobileControls.TextBox" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlTextBoxAdapter"/>
                <control name="System.Web.UI.MobileControls.Label" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlLabelAdapter"/>
                <control name="System.Web.UI.MobileControls.LiteralText" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlLiteralTextAdapter"/>
                <control name="System.Web.UI.MobileControls.Link" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlLinkAdapter"/>
                <control name="System.Web.UI.MobileControls.Command" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlCommandAdapter"/>
                <control name="System.Web.UI.MobileControls.PhoneCall" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlPhoneCallAdapter"/>
                <control name="System.Web.UI.MobileControls.List" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlListAdapter"/>
                <control name="System.Web.UI.MobileControls.SelectionList" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlSelectionListAdapter"/>
                <control name="System.Web.UI.MobileControls.ObjectList" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlObjectListAdapter"/>
                <control name="System.Web.UI.MobileControls.Image" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlImageAdapter"/>
                <control name="System.Web.UI.MobileControls.ValidationSummary" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlValidationSummaryAdapter"/>
                <control name="System.Web.UI.MobileControls.Calendar" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlCalendarAdapter"/>
                <control name="System.Web.UI.MobileControls.TextView" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlTextViewAdapter"/>
                <control name="System.Web.UI.MobileControls.MobileControl" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlControlAdapter"/>
                <control name="System.Web.UI.MobileControls.BaseValidator" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlValidatorAdapter"/>
            </device>
            <device name="HtmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.HtmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.HtmlPageAdapter">

                <control name="System.Web.UI.MobileControls.Panel" adapter="System.Web.UI.MobileControls.Adapters.HtmlPanelAdapter"/>
                <control name="System.Web.UI.MobileControls.Form" adapter="System.Web.UI.MobileControls.Adapters.HtmlFormAdapter"/>
                <control name="System.Web.UI.MobileControls.TextBox" adapter="System.Web.UI.MobileControls.Adapters.HtmlTextBoxAdapter"/>
                <control name="System.Web.UI.MobileControls.Label" adapter="System.Web.UI.MobileControls.Adapters.HtmlLabelAdapter"/>
                <control name="System.Web.UI.MobileControls.LiteralText" adapter="System.Web.UI.MobileControls.Adapters.HtmlLiteralTextAdapter"/>
                <control name="System.Web.UI.MobileControls.Link" adapter="System.Web.UI.MobileControls.Adapters.HtmlLinkAdapter"/>
                <control name="System.Web.UI.MobileControls.Command" adapter="System.Web.UI.MobileControls.Adapters.HtmlCommandAdapter"/>
                <control name="System.Web.UI.MobileControls.PhoneCall" adapter="System.Web.UI.MobileControls.Adapters.HtmlPhoneCallAdapter"/>
                <control name="System.Web.UI.MobileControls.List" adapter="System.Web.UI.MobileControls.Adapters.HtmlListAdapter"/>
                <control name="System.Web.UI.MobileControls.SelectionList" adapter="System.Web.UI.MobileControls.Adapters.HtmlSelectionListAdapter"/>
                <control name="System.Web.UI.MobileControls.ObjectList" adapter="System.Web.UI.MobileControls.Adapters.HtmlObjectListAdapter"/>
                <control name="System.Web.UI.MobileControls.Image" adapter="System.Web.UI.MobileControls.Adapters.HtmlImageAdapter"/>
                <control name="System.Web.UI.MobileControls.BaseValidator" adapter="System.Web.UI.MobileControls.Adapters.HtmlValidatorAdapter"/>
                <control name="System.Web.UI.MobileControls.ValidationSummary" adapter="System.Web.UI.MobileControls.Adapters.HtmlValidationSummaryAdapter"/>
                <control name="System.Web.UI.MobileControls.Calendar" adapter="System.Web.UI.MobileControls.Adapters.HtmlCalendarAdapter"/>
                <control name="System.Web.UI.MobileControls.TextView" adapter="System.Web.UI.MobileControls.Adapters.HtmlTextViewAdapter"/>
                <control name="System.Web.UI.MobileControls.MobileControl" adapter="System.Web.UI.MobileControls.Adapters.HtmlControlAdapter"/>
            </device>
            <device name="UpWmlDeviceAdapters" inheritsFrom="WmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.UpWmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.UpWmlPageAdapter">
            </device>
            <device name="WmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.WmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.WmlPageAdapter">

                <control name="System.Web.UI.MobileControls.Panel" adapter="System.Web.UI.MobileControls.Adapters.WmlPanelAdapter"/>
                <control name="System.Web.UI.MobileControls.Form" adapter="System.Web.UI.MobileControls.Adapters.WmlFormAdapter"/>
                <control name="System.Web.UI.MobileControls.TextBox" adapter="System.Web.UI.MobileControls.Adapters.WmlTextBoxAdapter"/>
                <control name="System.Web.UI.MobileControls.Label" adapter="System.Web.UI.MobileControls.Adapters.WmlLabelAdapter"/>
                <control name="System.Web.UI.MobileControls.LiteralText" adapter="System.Web.UI.MobileControls.Adapters.WmlLiteralTextAdapter"/>
                <control name="System.Web.UI.MobileControls.Link" adapter="System.Web.UI.MobileControls.Adapters.WmlLinkAdapter"/>
                <control name="System.Web.UI.MobileControls.Command" adapter="System.Web.UI.MobileControls.Adapters.WmlCommandAdapter"/>
                <control name="System.Web.UI.MobileControls.PhoneCall" adapter="System.Web.UI.MobileControls.Adapters.WmlPhoneCallAdapter"/>
                <control name="System.Web.UI.MobileControls.List" adapter="System.Web.UI.MobileControls.Adapters.WmlListAdapter"/>
                <control name="System.Web.UI.MobileControls.SelectionList" adapter="System.Web.UI.MobileControls.Adapters.WmlSelectionListAdapter"/>
                <control name="System.Web.UI.MobileControls.ObjectList" adapter="System.Web.UI.MobileControls.Adapters.WmlObjectListAdapter"/>
                <control name="System.Web.UI.MobileControls.Image" adapter="System.Web.UI.MobileControls.Adapters.WmlImageAdapter"/>
                <control name="System.Web.UI.MobileControls.BaseValidator" adapter="System.Web.UI.MobileControls.Adapters.WmlValidatorAdapter"/>
                <control name="System.Web.UI.MobileControls.ValidationSummary" adapter="System.Web.UI.MobileControls.Adapters.WmlValidationSummaryAdapter"/>
                <control name="System.Web.UI.MobileControls.Calendar" adapter="System.Web.UI.MobileControls.Adapters.WmlCalendarAdapter"/>
                <control name="System.Web.UI.MobileControls.TextView" adapter="System.Web.UI.MobileControls.Adapters.WmlTextViewAdapter"/>
                <control name="System.Web.UI.MobileControls.MobileControl" adapter="System.Web.UI.MobileControls.Adapters.WmlControlAdapter"/>
            </device>
            <device name="ChtmlDeviceAdapters" inheritsFrom="HtmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.ChtmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.ChtmlPageAdapter">

                <control name="System.Web.UI.MobileControls.Form" adapter="System.Web.UI.MobileControls.Adapters.ChtmlFormAdapter"/>
                <control name="System.Web.UI.MobileControls.Calendar" adapter="System.Web.UI.MobileControls.Adapters.ChtmlCalendarAdapter"/>
                <control name="System.Web.UI.MobileControls.Image" adapter="System.Web.UI.MobileControls.Adapters.ChtmlImageAdapter"/>
                <control name="System.Web.UI.MobileControls.TextBox" adapter="System.Web.UI.MobileControls.Adapters.ChtmlTextBoxAdapter"/>
                <control name="System.Web.UI.MobileControls.SelectionList" adapter="System.Web.UI.MobileControls.Adapters.ChtmlSelectionListAdapter"/>
                <control name="System.Web.UI.MobileControls.Command" adapter="System.Web.UI.MobileControls.Adapters.ChtmlCommandAdapter"/>
                <control name="System.Web.UI.MobileControls.PhoneCall" adapter="System.Web.UI.MobileControls.Adapters.ChtmlPhoneCallAdapter"/>
                <control name="System.Web.UI.MobileControls.Link" adapter="System.Web.UI.MobileControls.Adapters.ChtmlLinkAdapter"/>
            </device>
        </mobileControls>

        <pages>
            <namespaces>
                <add namespace="System"/>
                <add namespace="System.Collections"/>
                <add namespace="System.Collections.Specialized"/>
                <add namespace="System.Configuration"/>
                <add namespace="System.Text"/>
                <add namespace="System.Text.RegularExpressions"/>
                <add namespace="System.Web"/>
                <add namespace="System.Web.Caching"/>
                <add namespace="System.Web.SessionState"/>
                <add namespace="System.Web.Security"/>
                <add namespace="System.Web.Profile"/>
                <add namespace="System.Web.UI"/>
                <add namespace="System.Web.UI.WebControls"/>
                <add namespace="System.Web.UI.WebControls.WebParts"/>
                <add namespace="System.Web.UI.HtmlControls"/>
            </namespaces>

            <controls>
                <add tagPrefix="asp" namespace="System.Web.UI.WebControls.WebParts" assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            </controls>
        </pages>

        <protocols/>

        <siteMap>
            <providers>
                <add siteMapFile="web.sitemap" name="AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            </providers>
        </siteMap>

        <urlMappings enabled="true"/>

        <webControls clientScriptsLocation="/aspnet_client/{0}/{1}/"/>

        <webParts>
            <personalization>
                <providers>
                    <add connectionStringName="LocalSqlServer" name="AspNetSqlPersonalizationProvider" type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                </providers>

                <authorization>
                    <deny users="*" verbs="enterSharedScope"/>
                    <allow users="*" verbs="modifyState"/>
                </authorization>
            </personalization>

            <transformers>
                <add name="RowToFieldTransformer" type="System.Web.UI.WebControls.WebParts.RowToFieldTransformer"/>
                <add name="RowToParametersTransformer" type="System.Web.UI.WebControls.WebParts.RowToParametersTransformer"/>
            </transformers>
        </webParts>
    </system.web>
</configuration>
複製代碼

[3]asp.net網站IIS啓動的時候會加載配置文件中的配置信息,而後緩存這些信息,這樣就沒必要每次去讀取配置信息。在運行過程當中asp.net應用程序會監視配置文件的變化狀況,一旦編輯了這些配置信息,就會從新讀取這些配置信息並緩存。

[4]當咱們要讀取某個節點或者節點組信息時,是按照以下方式搜索的:
    (1)若是在當前頁面所在目錄下存在web.config文件,查看是否存在所要查找的結點名稱,若是存在返回結果並中止查找。
    (2)若是當前頁面所在目錄下不存在web.config文件或者web.config文件中不存在該結點名,則查找它的上級目錄,直到網站的根目錄。
    (3)若是網站根目錄下不存在web.config文件或者web.config文件中不存在該節點名則在%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config文件中查找。
    (4)若是在%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config文件中不存在相應結點,則在%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config文件中查找。
    (5)若是仍然沒有找到則返回null。

  因此若是咱們對某個網站或者某個文件夾有特定要求的配置,能夠在相應的文件夾下建立一個web.config文件,覆蓋掉上級文件夾中的web.config文件中的同名配置便可。這些配置信息的尋找只查找一次,之後便被緩存起來供後來的調用。在asp.net應用程序運行過程當中,若是web.config文件發生更改就會致使相應的應用程序從新啓動,這時存儲在服務器內存中的用戶會話信息就會丟失(如存儲在內存中的Session)。一些軟件(如殺毒軟件)每次完成對web.config的訪問時就會修改web.config的訪問時間屬性,也會致使asp.net應用程序的重啓。

 

二、配置文件節點說明

  web.config文件是一個XML文件,它的根結點是<configuration>,在<configuration>節點下的常見子節點有:<configSections>、<appSettings>、<connectionStrings>和<system.web>。     其中<appSettings>節點主要用於配置一些網站的應用配置信息,而<connectionStrings>節點主要用於配置網站的數據庫鏈接字符串信息。
<system.web>節點主要是網站運行時的一些配置,它的常見節點有以下:

[1]<appSettings>節點
  <appSettings>節點主要用來存儲asp.net應用程序的一些配置信息,好比上傳文件的保存路徑等,如下是一個例子:

<appSettings> 
    <!--容許上傳的圖片格式類型--> 
    <add key="ImageType" value=".jpg;.bmp;.gif;.png;.jpeg"/> 
    <!--容許上傳的文件類型--> 
    <add key="FileType" value=".jpg;.bmp;.gif;.png;.jpeg;.pdf;.zip;.rar;.xls;.doc"/> 
</appSettings>

  對於<appSettings>節點中的值能夠按照key來進行訪問,如下就是C#一個讀取key值爲「FileType」節點值的例子:

string fileType=ConfigurationManager.AppSettings["FileType "];

[2]<connectionStrings>節點
  <connectionStrings>節點主要用於配置數據庫鏈接的,咱們能夠<connectionStrings>節點中增長任意個節點來保存數據庫鏈接字符串,未來在代碼中經過代碼的方式動態獲取節點的值來實例化數據庫鏈接對象,這樣一旦部署的時候數據庫鏈接信息發生變化咱們僅須要更改此處的配置便可,而沒必要由於數據庫鏈接信息的變化而須要改動程序代碼和從新部署。
    如下就是一個<connectionStrings>節點配置的例子:

<connectionStrings> 
    <!--SQL Server數據庫配置--> 
    <add name="AspNetStudyConnectionString1" connectionString="Data Source=(local);Initial Catalog=AspNetStudy;User ID=sa;Password=sa"/> 
</connectionStrings>

  在代碼中咱們能夠這麼實例化數據庫鏈接對象:

//讀取web.config節點配置    
string connectionString = ConfigurationManager.ConnectionStrings["AspNetStudyConnectionString1"].ConnectionString; 
//實例化SqlConnection對象    
SqlConnection connection = new SqlConnection(connectionString);

  這樣作的好處是一旦開發時所用的數據庫和部署時的數據庫不一致,僅僅須要用記事本之類的文本編輯工具編輯connectionString屬性的值就好了。

[2]<compilation>節點
  <compilation>節點配置 ASP.NET 使用的全部編譯設置。默認的debug屬性爲「true」,即容許調試,在這種狀況下會影響網站的性能,因此在程序編譯完成交付使用以後應將其設爲「false」。

    <compilation debug="true">
        ......
    </compilation>

[4]<authentication>節點設置asp.net身份驗證模式,有四種身份驗證模式,它們的值分別以下:
Mode 驗證模式說明
1)Windows 使用Windows身份驗證,適用於域用戶或者局域網用戶。
2)Forms 使用表單驗證,依靠網站開發人員進行身份驗證。
3)Passport 使用微軟提供的身份驗證服務進行身份驗證。
4)None 不進行任何身份驗證。
<authentication>節點控制用戶對網站、目錄或者單獨頁的訪問,必須配合<authentication>節點一塊兒使用。

[5]<customErrors>節點
  <customErrors>節點用於定義一些自定義錯誤信息的信息。此節點有Mode和defaultRedirect兩個屬性,其中defaultRedirect屬性是一個可選屬性,表示應用程序發生錯誤時重定向到的默認URL,若是沒有指定該屬性則顯示通常性錯誤。Mode屬性是一個必選屬性,它有三個可能值,它們所表明的意義分別以下:
Mode值說明
1)On 表示在本地和遠程用戶都會看到自定義錯誤信息。
2)Off 禁用自定義錯誤信息,本地和遠程用戶都會看到詳細的錯誤信息。
3)RemoteOnly 表示本地用戶將看到詳細錯誤信息,而遠程用戶將會看到自定義錯誤信息。
  這裏有必要說明一下本地用戶和遠程用戶的概念。當咱們訪問asp.net應用程時所使用的機器和發佈asp.net應用程序所使用的機器爲同一臺機器時成爲本地用戶,反之則稱之爲遠程用戶。在開發調試階段爲了便於查找錯誤Mode屬性建議設置爲Off,而在部署階段應將Mode屬性設置爲On或者RemoteOnly,以免這些詳細的錯誤信息暴露了程序代碼細節從而引來黑客的入侵。
  下面咱們添加一個頁面CustomErrorsDemo.aspx,在它的Page_Load事件裏拋出一個異常,代碼以下:

複製代碼
public partial class CustomErrorsDemo : System.Web.UI.Page 
{ 
    void Page_Load() void Page_Load(object sender, EventArgs e) 
    { 
      throw new Exception("故意拋出的異常。"); 
    } 
}
複製代碼

先配置<customErrors>以下:

<customErrors mode="RemoteOnly"> 
    <error statusCode="403" redirect="NoAccess.htm" /> 
    <error statusCode="404" redirect="FileNotFound.htm" /> 
</customErrors>

  

[6]<error>子節點
  在<customErrors>節點下還包含有<error>子節點,這個節點主要是根據服務器的HTTP錯誤狀態代碼而重定向到咱們自定義的錯誤頁面,注意要使<error>子節點下的配置生效,必須將<customErrors>節點節點的Mode屬性設置爲「On」。下面是一個例子:
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm"> 
    <error statusCode="403" redirect="403.htm" /> 
    <error statusCode="404" redirect="404.htm" /> 
</customErrors>

  在上面的配置中若是用戶訪問的頁面不存在就會跳轉到404.htm頁面,若是用戶沒有權限訪問請求的頁面則會跳轉到403.htm頁面,403.htm和404.htm頁面都是咱們本身添加的頁面,咱們能夠在頁面中給出友好的錯誤提示。

[7]<httpHandlers>節點
  <httpHandlers>節點用於根據用戶請求的URL和HTTP謂詞將用戶的請求交給相應的處理程序。能夠在配置級別的任何層次配置此節點,也就是說能夠針對某個特定目錄下指定的特殊文件進行特殊處理。
  查看machine.config文件同一目錄下的web.config文件中的<httpHandlers>節點配置:

<httpHandlers>
  ......
    <add path="*.mdf" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/> 
    <add path="*.ldf" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/> 
  ......
</httpHandlers>

  從上面的配置中能夠看出,針對*.mdf、*.ldf文件的Get或者Post請求都會交給System.Web.HttpForbiddenHandler來處理,處理的結果就是用戶不能查看或者下載相關的文件。若是咱們某個文件夾下的文件或者某個類型的文件不容許用戶下載,能夠在</httpHandlers>節點中增長相應的子節點。
  下面咱們以一個例子來講明<httpHandlers>節點的用法,在咱們的asp.net應用程序中創建一個IPData目錄,在IPData目錄中建立一個IPData.txt文件,而後在Web.config中添加如下配置:

<httpHandlers> 
    <add path="IPData/*.txt" verb="*" type="System.Web.HttpForbiddenHandler"/> 
</httpHandlers>

  上面的代碼的做用是禁止訪問IPData目錄下的任何txt文件。
  而後新建一個頁面,在頁面中添加一個超級連接,連接到該目錄下IPData.txt文件,代碼以下:
複製代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HttpHandlersDemo.aspx.cs" Inherits="HttpHandlersDemo" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>httpHandlers節點的例子</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <a href="IPData/IPData.txt" title="打開IPData/IPData.txt">打開IPData/IPData.txt</a> 
    </div> 
    </form> 
</body> 
</html>
複製代碼

  運行這個頁面的效果以下:
  

 
  當前web.config文件的<customErrors>節點配置以下:
  <customErrors mode="On" defaultRedirect="GenericErrorPage.htm"> 
      <error statusCode="403" redirect="403.htm" /> 
      <error statusCode="404" redirect="404.htm" /> 
  </customErrors>
  若是存在403.htm和404.htm頁面,點擊超級連接以後會出現以下效果:
  
  咱們從上圖中能夠看到當<customErrors>節點的Mode屬性爲「On」時,由於被禁止訪問IPData文件夾下的全部txt文件,因此會跳轉到自定義的沒有權限提示頁面,即403.htm。

[8]<httpRuntime>節點
  <httpRuntime>節點用於對 ASP.NET HTTP 運行庫設置。該節能夠在計算機、站點、應用程序和子目錄級別聲明。
  例以下面的配置控制用戶最大能上傳的文件爲40M(40*1024K),最大超時時間爲60秒,最大併發請求爲100個。
<httpRuntime maxRequestLength="40960" executionTimeout="60" appRequestQueueLimit="100"/>

[9]<pages>節點

<pages>節點用於表示對特定頁設置,主要有三個屬性,分別以下:
屬性名           說明
buffer          是否啓用了 HTTP 響應緩衝。
enableViewStateMac   是否應該對頁的視圖狀態運行計算機身份驗證檢查 (MAC),以放置用戶篡改,默認爲false,若是設置爲true將會引發性能的下降。
validateRequest     是否驗證用戶輸入中有跨站點腳本攻擊和SQL注入式漏洞攻擊,默認爲true,若是出現匹配狀況就會發 HttpRequestValidationException 異常。對於包含有在線文本編輯器頁面通常自行驗證用戶輸入而將此屬性設爲false。

下面就是一個配置節點的例子:
<pages buffer="true" enableViewStateMac="true" validateRequest="false"/>

[10]<sessionState>節點
<sessionState>節點用於配置當前asp.net應用程序的會話狀態配置。如下就是一個常見配置:

<sessionState cookieless="false" mode="InProc" timeout="30" />

       上面的節點配置是設置在asp.net應用程序中啓用Cookie,而且指定會話狀態模式爲在進程中保存會話狀態,同時還指定了會話超時爲30分鐘。
<sessionState>節點的Mode屬性能夠是如下幾種值之一:
屬性值       說明
Custom     使用自定義數據來存儲會話狀態數據。
InProc       默認值。由asp.net輔助進程來存儲會話狀態數據。
Off        禁用會話狀態。
SQLServer    使用進程外SQL Server數據庫保存會話狀態數據。
StateServer    使用進程外 ASP.NET 狀態服務存儲狀態信息。
  通常默認狀況下使用InProc模式來存儲會話狀態數據,這種模式的好處是存取速度快,缺點是比較佔用內存,因此不宜在這種模式下存儲大型的用戶會話數據。
[11]<globalization>節點:
  用於配置應用程序的全球化設置。此節點有幾個比較重要的屬性,分別以下:
屬性名           說明
fileEncoding     可選屬性。設置.aspx、.asmx 和 .asax 文件的存儲編碼。
requestEncoding    可選屬性。設置客戶端請求的編碼,默認爲UTF-8.
responseEncoding  可選屬性。設置服務器端響應的編碼,默認爲UTF-8.
如下就是asp.net應用程序中的默認配置:

<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>

 
三、配置文件的讀寫操做
  雖然web.config文件是一個XML文件,可是因爲權限的緣由它在部署中不能像操做普通XML文件那樣進行修改,在.net中提供了一個類用於對web.config進行修改。
  下面是針對web.config修改通用類的代碼:

複製代碼
using System; 
using System.Configuration; 
using System.Web; 
using System.Web.Configuration; 
/// <summary>    
/// ConfigurationOperator 的摘要說明    
/// </summary>    
public class ConfigurationOperator:IDisposable 
{ 
    private Configuration config; 

    ConfigurationOperator():this(HttpContext.Current.Request.ApplicationPath) 
    { 
        
    } 

    ConfigurationOperator(string path) 
    { 
        config = WebConfigurationManager.OpenWebConfiguration(path); 
    } 

    /// <summary>     
    /// 設置應用程序配置節點,若是已經存在此節點,則會修改該節點的值,不然添加此節點    
    /// </summary>     
    /// <param name="key">節點名稱</param>     
    /// <param name="value">節點值</param>     
    void SetAppSetting(string key, string value) 
    { 
        AppSettingsSection appSetting = (AppSettingsSection)config.GetSection("appSettings"); 
        if (appSetting.Settings[key] == null)//若是不存在此節點,則添加     
        { 
            appSetting.Settings.Add(key, value); 
        } 
        else//若是存在此節點,則修改     
        { 
            appSetting.Settings[key].Value = value; 
        } 
    } 

    /// <summary>     
    /// 設置數據庫鏈接字符串節點,若是不存在此節點,則會添加此節點及對應的值,存在則修改     
    /// </summary>     
    /// <param name="key">節點名稱</param>     
    /// <param name="value">節點值</param>     
    void SetConnectionString(string key, string connectionString) 
    { 
        ConnectionStringsSection connectionSetting = (ConnectionStringsSection)config.GetSection("connectionStrings"); 
        if (connectionSetting.ConnectionStrings[key] == null)//若是不存在此節點,則添加     
        { 
            ConnectionStringSettings connectionStringSettings = new ConnectionStringSettings(key, connectionString); 
            connectionSetting.ConnectionStrings.Add(connectionStringSettings); 
        } 
        else//若是存在此節點,則修改     
        { 
            connectionSetting.ConnectionStrings[key].ConnectionString = connectionString; 
        } 
    } 

    /// <summary>     
    /// 保存所做的修改     
    /// </summary>     
    void Save() 
    { 
        config.Save(); 
        config = null; 
    } 

    void Dispose() 
    { 
        if (config != null) 
        { 
            config.Save(); 
        } 
    } 
} 
複製代碼


  把上面的代碼存放到App_Code文件夾下,咱們在項目中就能夠直接使用了。
  咱們經過一個例子演示若是使用這個通用類對web.config進行設置。新建一個aspx頁面,下面是前臺代碼:

複製代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConfigModifyDemo.aspx.cs" Inherits="ConfigModifyDemo" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>在部署後修改web.config的例子</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <table border="0" cellpadding="0" cellspacing="0"> 
    <tr><td>類型</td><td>名稱</td><td>值</td></tr> 
    <tr><td> 
    程序配置</td><td> 
    <asp:TextBox ID="txtKey" runat="server"></asp:TextBox> 
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtKey" 
    ErrorMessage="*" Display="Dynamic"></asp:RequiredFieldValidator></td><td> 
    <asp:TextBox ID="txtAppSetting" runat="server"></asp:TextBox></td></tr> 
    <tr><td> 
    數據庫鏈接</td><td> 
    <asp:TextBox ID="txtConnectionName" runat="server"></asp:TextBox> 
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtConnectionName" 
    Display="Dynamic"></asp:RequiredFieldValidator></td><td style="height: 24px"> <asp:TextBox ID="txtConnectionString" runat="server"></asp:TextBox></td></tr> <tr><td> <asp:Button ID="btnModify" runat="server" OnClick="btnModify_Click" Text="修改" /></td><td></td><td></td></tr> </table> </div> </form> </body> </html>
複製代碼
  編寫後臺代碼有時可能須要增長對配置文件讀寫操做類所在dll (System.Configuration) 的引用,以下:
  
  下面是後臺代碼:
 
複製代碼
using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Web.Configuration;//注意添加這個命名空間    
public partial class ConfigModifyDemo : System.Web.UI.Page 
{ 
     void Page_Load(object sender, EventArgs e) 
    { 
    } 
    void btnModify_Click(object sender, EventArgs e) 
    { 
        string appSetting = txtAppSetting.Text;//appSetting子節點值    
        string connectionString = txtConnectionString.Text;//鏈接字符串    
        string key = txtKey.Text;//appSetting子節點Key    
        string connectionName = txtConnectionName.Text;//鏈接Name    
        ConfigurationOperator op = new ConfigurationOperator(); 
        op.SetAppSetting(key, appSetting); 
        op.SetConnectionString(connectionName, connectionString); 
        op.Save(); 
    } } 
複製代碼

  下面是運行界面:
  

咱們在上面的表單中填入以下信息:
  
假設此時web.config文件相關節點的內容以下:
<appSettings> 
    </appSettings> 
    <connectionStrings> 
        <add name="Conn" connectionString="Data Source=(local);Initial Catalog=AspNetStudy;Persist Security Info=True;User ID=sa;Password=sa" /> 
    </connectionStrings>
咱們點擊「修改」按鈕以後的文件內容以下:
<appSettings> 
        <add key="country" value="china" /> 
    </appSettings> 
    <connectionStrings> 
        <add name="Conn" connectionString="Data Source=(local);Initial Catalog=Study;User ID=sa;Password=sa" 
            providerName="System.Data.SqlClient" /> 
    </connectionStrings>
        從執行結果能夠看出咱們的程序確實能作到修改和添加web.config中的節點的功能。須要注意的是,在利用了某些版本控制軟件以後(如Microsoft Visual SourceSafe),版本控制軟件可能會將web.config設置爲只讀屬性,就會出現不能設置的狀況,咱們須要手動將web.config的只讀屬性去掉才能設置web.config文件。在實際部署項目的時候就不會存在這個問題。
        總結:web.config是asp.net應用程序中一個很重要的配置文件,經過web.config文件能夠方便咱們進行開發和部署asp.net應用程序。此外還能對程序進行一些靈活的控制。在本篇中詳細講述了各節點的做用。由於在部署asp.net應用程序後由於權限緣由不能按照XML方式進行修改web.config文件,因此在本篇中還提供了一個針對<appSettings>節點和<connectionStrings>節點設置的通用類。

  因爲Web.config在使用時很靈活,能夠自定義一些節點。因此這裏只介紹一些比較經常使用的節點。

複製代碼
<?xml version="1.0"?>

<!--注意: 除了手動編輯此文件之外,您還可使用 Web 管理工具來配置應用程序的設置。可使用 Visual Studio 中的「項目」->「Asp.Net 配置」選項。
設置和註釋的完整列表在 machine.config.comments 中,該文件一般位於 "Windows" Microsoft.Net"Framework"v2.x"Config 中。-->

<!--Webconfig文件是一個xml文件,configuration 是xml文件的根節點,因爲xml文件的根節點只能有一個,因此Webconfig的全部配置都是在這個節點內進行的。-->
<configuration>

  <!--指定配置節和命名空間聲明。clear:移除對繼承的節和節組的全部引用,只容許由當前 section 和 sectionGroup 元素添加的節和節組。
  remove:移除對繼承的節和節組的引用。-->
  <configSections>
    <!--sectionGroup:定義配置節處理程序與配置節之間的關聯-->
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
        </sectionGroup>
      </sectionGroup>

      <!--section:定義配置節處理程序與配置元素之間的關聯-->
      <section name="rewriter" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />

  </configSections>

  <!--appSettings是應用程序設置,能夠定義應用程序的全局常量設置等信息-->
  <appSettings>
    <add key="1" value="1" />
    <add key="gao" value="weipeng" />
  </appSettings>

  <!--鏈接字符串設置-->
  <connectionStrings>
    <add name="ConnString" connectionString="Data Source=GAO;Initial Catalog=HBWXDate;User ID=sa;password=sa"></add>
    <add name="111" connectionString="11111" />
  </connectionStrings>

  <!--指定應用子配置設置的資源,並鎖定配置設置,以防止它們被子配置文件重寫。page指定應用包含的配置設置的資源.allowOverride是否容許配置文件的重寫,提升配置文件的安全性-->
  <location path="Default.aspx" allowOverride="false">

    <!--控制asp.net運行時的行爲-->
    <system.web>

      <!--identity控制web應用程序的身份驗證標識.-->
      <identity impersonate="false" />

      <!--標識特定於頁的配置設置(如是否啓用會話狀態、視圖狀態,是否檢測用戶的輸入等)。<pages>能夠在計算機、站點、應用程序和子目錄級別聲明.
        如下設置是默認主頁爲Index,主題是Default,不檢測用戶在瀏覽器輸入的內容中是否存在潛在的危險數據(注:該項默認是檢測,若是你使用了不檢測,一要對用戶的輸入進行編碼或驗證),在從客戶端回發頁時將檢查加密的視圖狀態,以驗證視圖狀態是否已在客戶端被篡改。(注:該項默認是不驗證)禁用ViewState-->
      <pages masterPageFile="Index" theme="Default" buffer="true" enableViewStateMac="true" validateRequest="false" enableViewState="false">

        <!--controls 元素定義標記前綴所在的 register 指令和命名空間的集合-->
        <controls></controls>

        <!--將在程序集預編譯期間使用的導入指令的集合-->
        <namespaces></namespaces>

      </pages>

      <!--默認錯誤頁設置,mode:具備On,Off,RemoteOnly 3種狀態。On表示始終顯示自定義的信息; Off表示始終顯示詳細的asp.net錯誤信息; RemoteOnly表示只對不在本地Web服務器上運行的用戶顯示自定義信息.defaultRedirect:用於出現錯誤時重定向的URL地址-->
      <customErrors defaultRedirect="Err.html" mode="RemoteOnly">
        <!--特殊代碼編號的錯誤從定向文件-->
        <error statusCode="403" redirect="NoAccess.htm" />
        <error statusCode="404" redirect="FileNotFound.htm" />
      </customErrors>

      <!--配置調試和跟蹤:下面配置的意思是啓動調試(默認),捕獲跟蹤信息,要緩存的跟蹤請求個數(15),跟蹤結果的排列順序-->
      <trace enabled="true" localOnly="false" pageOutput="true" requestLimit="15" traceMode="SortByCategory"/>

      <!-- 設置 debug="true" 將調試符號插入已編譯的頁面中。但因爲這會影響性能,所以只在開發過程當中將此值設置爲 true。設置默認的開發語言C#。batch是否支持批處理-->
      <compilation debug="true" defaultLanguage="c#" batch="false">

        <assemblies>
          <!--加的程序集引用,每添加一個程序集,就表示你的應用程序已經依賴了一個程序集,你就能夠在你的應用程序中使用了-->
          <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        </assemblies>

        <!--定義用於編譯自定義資源文件的生成提供程序的集合。-->
        <buildProviders>
          <!---->
          <add extension=".aspx" type="System.Web.Compilation.PageBuildProvider"/>
          <add extension=".ascx" type="System.Web.Compilation.UserControlBuildProvider"/>
          <add extension=".master" type="System.Web.Compilation.MasterPageBuildProvider"/>
          <add extension=".asmx" type="System.Web.Compilation.WebServiceBuildProvider"/>
          <add extension=".ashx" type="System.Web.Compilation.WebHandlerBuildProvider"/>
          <add extension=".soap" type="System.Web.Compilation.WebServiceBuildProvider"/>
          <add extension=".resx" type="System.Web.Compilation.ResXBuildProvider"/>
          <add extension=".resources" type="System.Web.Compilation.ResourcesBuildProvider"/>
          <add extension=".wsdl" type="System.Web.Compilation.WsdlBuildProvider"/>
          <add extension=".xsd" type="System.Web.Compilation.XsdBuildProvider"/>
          <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </buildProviders>

      </compilation>

      <!--經過 <authentication> 節能夠配置 ASP.NET 使用的 安全身份驗證模式,以標識傳入的用戶。
      Windows: 使用IIS驗證方式;Forms: 使用基於窗體的驗證方式;Passport: 採用Passport cookie驗證模式,;one: 不採用任何驗證方式-->
      <authentication mode="Forms">
        <!--Name: 指定完成身份驗證的Http cookie的名稱;LoginUrl: 若是未經過驗證或超時後重定向的頁面URL,通常爲登陸頁面,讓用戶從新登陸;
          Protection: 指定 cookie數據的保護方式,可設置爲:All表示加密數據,並進行有效性驗證兩種方式,None表示不保護Cookie,Encryption表示對Cookie內容進行加密,validation表示對Cookie內容進行有效性驗證,
          TimeOut: 指定Cookie的失效時間. 超時後要從新登陸。-->
        <forms name=".ASPXUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30"/>
      </authentication>

      <!--控制對 URL 資源的客戶端訪問(如容許匿名用戶訪問)。此元素能夠在任何級別(計算機、站點、應用程序、子目錄或頁)上聲明。必需與<authentication> 節配合使用。
      此處的意思是對匿名用戶不進行身份驗證。拒絕用戶customer-->
      <authorization>
        <allow users="*"/>
        <deny users="customer"/>
        <allow users="aa" roles="aa" />
      </authorization>

      <!--站點全球化設置,requestEncoding: 它用來檢查每個發來請求的編碼;responseEncoding: 用於檢查發回的響應內容編碼;
      fileEncoding:用於檢查aspx,asax等文件解析的默認編碼,默認的編碼是utf-8-->
      <globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312" />

      <!--會話狀態設置。mode: 分爲off,Inproc,StateServer,SqlServer幾種狀態 InProc 存儲在進程中特色:具備最佳的性能,速度最快,但不能跨多臺服務器存儲共享; 
      StateServer 存儲在狀態服務器中特色:當須要跨服務器維護用戶會話信息時,使用此方法。可是信息存儲在狀態服務器上,一旦狀態服務器出現故障,信息將丟失;
      SqlServer 存儲在sql server中特色:工做負載會變大,但信息不會丟失; stateConnectionString :指定asp.net應用程序存儲遠程會話狀態的服務器名,默認爲本機。
      sqlConnectionString:當用會話狀態數據庫時,在這裏設置鏈接字符串。Cookieless:設置爲flase時,表示使用cookie會話狀態來標識客戶.timeout表示會話超時時間。-->
      <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"></sessionState>

      <!--爲 ASP.NET 應用程序配置頁的視圖狀態設置。設置要存儲在頁歷史記錄中的項數。-->
      <sessionPageState historySize="9"/>

      <!--配置asp.net http運行庫的設置。能夠在計算機,站點,應用程序和子目錄級別聲明
    容許最多的請求個數100,最長容許執行請求時間爲80秒,控制用戶上傳文件的大小,默認是4M。useFullyQualifiedRedirectUrl客戶端重定向不須要被自動轉換爲徹底限定格式。-->
      <httpRuntime appRequestQueueLimit="100" executionTimeout="80" maxRequestLength="40960" useFullyQualifiedRedirectUrl="false"/>

      <!--httpModules在一個應用程序內配置 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="RoleManager" type="System.Web.Security.RoleManagerModule" />
        <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
        <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
        <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule" />
        <!--自定義的URL重寫,type基本上就是dll名-->
        <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
        <add name="Profile" type="System.Web.Profile.ProfileModule" />
      </httpModules>

      <!--httpHandlers用於根據用戶請求的URL和HTTP謂詞將用戶的請求交給相應的處理程序。能夠在配置級別的任何層次配置此節點,也就是說能夠針對某個特定目錄下指定的特殊文件進行特殊處理。
    add:指定映射處處理程序的謂詞/路徑。clear:移除當前已配置或已繼承的全部處理程序映射。remove:移除映射處處理程序的謂詞/路徑。remove 指令必須與前一個 add 指令的謂詞/路徑組合徹底匹配。該指令不支持通配符。-->
      <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
        <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
      </httpHandlers>

      <!--爲 Web 應用程序使用的 Cookie 配置屬性。domain:設置 Cookie 域名。httpOnlyCookies:在 Internet Explorer 6 SP1 中啓用 HttpOnlyCookies Cookie 的輸出。默認值爲 false。requireSSL:獲取一個指示是否須要安全套接字層 (SSL) 通訊的值.-->
      <httpCookies httpOnlyCookies="false" requireSSL="false"/>
      <!--控制 ASP.NET Web 服務及其客戶端的行爲。protocols:指定傳輸協議,ASP.NET 可以使用這些傳輸協議來解密 HTTP-->
      <webServices>
        <protocols>
          <add/>
        </protocols>
      </webServices>

      <!--爲 Web 應用程序配置緩存設置。cache:定義全局應用程序緩存設置。outputCache :指定應用程序範圍的輸出緩存設置。outputCacheSettings:指定能夠應用於應用程序中頁的輸出緩存設置。sqlCacheDependency:爲 ASP.NET 應用程序配置 SQL 緩存依賴項。-->
      <caching>
        <cache disableMemoryCollection = "false" disableExpiration = "false" privateBytesLimit = "0" percentagePhysicalMemoryUsedLimit = "90" privateBytesPollTime = "00:02:00"/>
        <!--設計須要以這種方式緩存的頁時,您須要向該頁添加如下指令:<%@ OutputCache CacheProfile="ServerOnly" %>-->
        <outputCacheSettings>
          <outputCacheProfiles>
            <add name="ServerOnly" duration="60" varyByCustom="browser" location="Server" />
          </outputCacheProfiles>
        </outputCacheSettings>
      </caching>
    </system.web>
  </location>

  <!--網絡設置,authenticationModules:指定用於對 Internet 請求進行身份驗證的模塊。connectionManagement:指定與 Internet 宿主的鏈接的最大數目。defaultProxy:配置超文本傳輸協議 (HTTP) 代理服務器。
  mailSettings:配置簡單郵件傳輸協議 (SMTP) 郵件發送選項。requestCaching:控制網絡請求的緩存機制。settings:配置 System.Net 的基本網絡選項。-->
  <system.net>
    <!--配置SMTP電子郵件設置-->
    <mailSettings>
      <smtp from="weipeng">
        <network host="Gao" password="" userName="" />
      </smtp>
    </mailSettings>

    <!--禁用全部緩存-->
    <requestCaching disableAllCaching="true"></requestCaching>

    <!--指定代理地址,並對本地訪問和 contoso.com 跳過代理。-->
    <defaultProxy>
      <proxy usesystemdefault="True" proxyaddress="http://192.168.1.10:3128" bypassonlocal="True"/>
      <bypasslist>
        <add address="[a-z]+".contoso=""".com" />
      </bypasslist>
    </defaultProxy>

  </system.net>

  <!--該節替換在 httpHandlers 和 httpModules 節中添加的與 AJAX 相關的 HTTP 處理程序和模塊。該節使 IIS 7.0 在集成模式下運行時可以使用這些處理程序和模塊。在iis7.0 下運行 ASP.NET AJAX 須要 system.webServer 
  節。對早期版本的 IIS 來講則不須要此節。 -->
  <system.webServer>

    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </modules>

    <handlers>
      <remove name="WebServiceHandlerFactory-Integrated"/>
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>

  </system.webServer>

  <!--ASP.NET AJAX 中配置 ASP.NET 服務-->
  <system.web.extensions>

    <!--配置 JSON 序列化-->
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="5000"/>
      </webServices>
    </scripting>

  </system.web.extensions>

  <!--對WCF的相關配置-->
  <system.serviceModel>

    <services>
      <service name="WCFStudent.WCFStudentText" behaviorConfiguration="ServiceBehavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding" contract="WCFStudent.IStuServiceContract">
          <!-- 部署時,應刪除或替換下列標識元素,以反映在其下運行部署服務的標識。刪除以後,WCF 將自動推導相應標識。-->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- 爲避免泄漏元數據信息,請在部署前將如下值設置爲 false 並刪除上面的元數據終結點 -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- 要接收故障異常詳細信息以進行調試,請將如下值設置爲 true。在部署前設置爲 false 以免泄漏異常信息-->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

  <!--URL重定向-->
  <rewriter>
    <rewrite url="~/user/u(.+).aspx" to="~/user/index.aspx?r=$1" />
    <rewrite url="~/ask/q(.+).aspx" to="~/home/ask/content.aspx?id=$1" />
    <rewrite url="~/blog/b(.+).aspx" to="~/home/blog/article.aspx?r=$1" />
    <rewrite url="~/news/n(.+).aspx" to="~/home/news/content.aspx?nid=$1" />
    <rewrite url="~/default.aspx" to="~/home/ram/net.aspx" />
  </rewriter>

</configuration>
複製代碼
相關文章
相關標籤/搜索