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


  在asp.net中配置文件名一般默認是web.config。每個web.config文件都是基於XML的文本文件,並且可以保存到Web應用程序中的任何目錄中。在發布Web應用程序時web.config文件並不編譯進dll文件中。如果將來客戶端發生了變化,僅僅需要用記事本打開web.config文件編輯相關設置就可以重新正常使用,非常方便。

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

[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>
machine.comfig

[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>
View Code

[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應用程序的重啟。

 

2、配置文件節點說明

  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"/>

 
3、配置文件的讀寫操作
  雖然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(); 
    } } 
后台Code

  下面是運行界面:
  

我們在上面的表單中填入如下信息:
  
假設此時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>
Web.config 實例

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM