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

2019-09-11 14:39:01 浏览数 (1)

  在asp.net中配置文件名一般默认是web.config。每个web.config文件都是基于XML的文本文件,并且可以保存到Web应用程序中的任何目录中。在发布Web应用程序时web.config文件并不编译进dll文件中。如果将来客户端发生了变化,仅仅需要用记事本打开web.config文件编辑相关设置就可以重新正常使用,非常方便。

1、配置文件的查找优先级

[1]在.net提供了一个针对当前机器的配置文件,这个文件是machine.config,它位于%windir%Microsoft.NETFrameworkv2.0.50727CONFIG文件下(%windir%是系统分区下的系统目录,在命令行模式下输入%windir%然后回车就能查看当前机器的系统目录,在Windows7及Windows10中%windir%是系统分区下的windows目录,这个文件里面定义了针对当前机器的WinForm程序和asp.net应用程序的配置。下面是machine.config文件的内容:

代码语言:javascript复制
<?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文件的内容:

代码语言:javascript复制
<?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.NETFrameworkv2.0.50727CONFIGweb.config文件中查找。 (4)如果在%windir%Microsoft.NETFrameworkv2.0.50727CONFIGweb.config文件中不存在相应结点,则在%windir%Microsoft.NETFrameworkv2.0.50727CONFIGmachine.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应用程序的一些配置信息,比如上传文件的保存路径等,以下是一个例子:

代码语言:javascript复制
<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”节点值的例子:

代码语言:javascript复制
string fileType=ConfigurationManager.AppSettings["FileType "];

[2]<connectionStrings>节点   <connectionStrings>节点主要用于配置数据库连接的,我们可以<connectionStrings>节点中增加任意个节点来保存数据库连接字符串,将来在代码中通过代码的方式动态获取节点的值来实例化数据库连接对象,这样一旦部署的时候数据库连接信息发生变化我们仅需要更改此处的配置即可,而不必因为数据库连接信息的变化而需要改动程序代码和重新部署。 以下就是一个<connectionStrings>节点配置的例子:

代码语言:javascript复制
<connectionStrings> 
    <!--SQL Server数据库配置--> 
    <add name="AspNetStudyConnectionString1" connectionString="Data Source=(local);Initial Catalog=AspNetStudy;User ID=sa;Password=sa"/> 
</connectionStrings>

  在代码中我们可以这么实例化数据库连接对象:

代码语言:javascript复制
//读取web.config节点配置    
string connectionString = ConfigurationManager.ConnectionStrings["AspNetStudyConnectionString1"].ConnectionString; 
//实例化SqlConnection对象    
SqlConnection connection = new SqlConnection(connectionString);

  这样做的好处是一旦开发时所用的数据库和部署时的数据库不一致,仅仅需要用记事本之类的文本编辑工具编辑connectionString属性的值就行了。 [2]<compilation>节点   <compilation>节点配置 ASP.NET 使用的所有编译设置。默认的debug属性为“true”,即允许调试,在这种情况下会影响网站的性能,所以在程序编译完成交付使用之后应将其设为“false”。

代码语言:javascript复制
    <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事件里抛出一个异常,代码如下:

代码语言:javascript复制
public partial class CustomErrorsDemo : System.Web.UI.Page 
{ 
    void Page_Load() void Page_Load(object sender, EventArgs e) 
    { 
      throw new Exception("故意抛出的异常。"); 
    } 
}

先配置<customErrors>如下:

代码语言:javascript复制
<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”。下面是一个例子:

代码语言:javascript复制
<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>节点配置:

代码语言:javascript复制
<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文件,代码如下:

代码语言:javascript复制
<%@ 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个。

代码语言:javascript复制
<httpRuntime maxRequestLength="40960" executionTimeout="60" appRequestQueueLimit="100"/>

[9]<pages>节点

<pages>节点用于表示对特定页设置,主要有三个属性,分别如下: 属性名           说明 buffer          是否启用了 HTTP 响应缓冲。 enableViewStateMac   是否应该对页的视图状态运行计算机身份验证检查 (MAC),以放置用户篡改,默认为false,如果设置为true将会引起性能的降低。 validateRequest     是否验证用户输入中有跨站点脚本攻击和SQL注入式漏洞攻击,默认为true,如果出现匹配情况就会发 HttpRequestValidationException 异常。对于包含有在线文本编辑器页面一般自行验证用户输入而将此属性设为false。

下面就是一个配置节点的例子:

代码语言:javascript复制
<pages buffer="true" enableViewStateMac="true" validateRequest="false"/>

[10]<sessionState>节点 <sessionState>节点用于配置当前asp.net应用程序的会话状态配置。以下就是一个常见配置:

代码语言:javascript复制
<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应用程序中的默认配置:

代码语言:javascript复制
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>

3、配置文件的读写操作   虽然web.config文件是一个XML文件,但是由于权限的原因它在部署中不能像操作普通XML文件那样进行修改,在.net中提供了一个类用于对web.config进行修改。   下面是针对web.config修改通用类的代码:

代码语言:javascript复制
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页面,下面是前台代码:

代码语言:javascript复制
<%@ 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) 的引用,如下:

  下面是后台代码:

代码语言:javascript复制
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在使用时很灵活,可以自定义一些节点。所以这里只介绍一些比较常用的节点。

代码语言:javascript复制
<?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>

0 人点赞