asp.net 中的 WebConfig配置文件详解

<?xml version="1.0"?>

<!--Webconfig的一般执行顺序:

1.当前文件夹

2.父文件夹

3.Framework自定义的两个config文件(web.config和machine.config)

注意:

子目录的配置设置可以提供除从父目录继承的配置信息以外的配置信息,也可以重写或修改父目录中定义的设置。

运行时对Web.config文件的修改不需要重启服务就可以生效(注:<processModel> 节例外);

Web.config文件是可以扩展的。你可以自定义新配置参数并编写配置节处理程序以对它们进行处理;

web.config配置文件(默认的配置设置)以下所有的代码都应该位于<system.web></system.web>之间

-->

<configuration>

<!--configuration 节根元素,其它节都是在它的内部-->

<!--配置节处理程序声明 特点:位于配置文件的顶部,包含在<configSections>-->

<!--自定义Web.config文件配置节过程分为两步。

1.在配置文件顶部 <configSections> 和 </configSections>标记之间声明配置节的名称和处理该节中配置数据的 .NET Framework 类的名称。

2.是在 <configSections> 区域之后为声明的节做实际的配置设置。

-->

<configSections>

<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>

<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>

<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>

<section name="ore.SiebelWrite" type="ORE.SiebelWrite.DataAccess.Bases.NetTiersServiceSection, ORE.SiebelWrite.DataAccess" allowDefinition="MachineToApplication" restartOnExternalChanges="true"/>

<!--配置节组

特点: 用用<sectionGroup>标记,可以自定义分组,可以放到<configSections>内部或其它<sectionGroup>标记的内部

-->

<sectionGroup name="ore">

<section name="data" type="ORE.Framework.Providers.ProviderConfigurationHandler, ORE.Framework"/>

<section name="scheduling" type="ORE.Framework.Providers.ProviderConfigurationHandler, ORE.Framework"/>

</sectionGroup>

<!--示例:创建一个节存储数据库连接字符串-->

<section name="appSettings" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

</configSections>

<enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source">

<sources>

<add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" filePath="entlib.config"/>

</sources>

</enterpriseLibrary.ConfigurationSource>

<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">

<listeners>

<add databaseInstanceName="ORE" writeLogStoredProcName="WriteLog" addCategoryStoredProcName="AddCategory" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Database Trace Listener"/>

</listeners>

<formatters>

<add template="Timestamp: {timestamp} Message: {message} Category: {category} Priority: {priority} EventId: {eventid} Severity: {severity} Title:{title} Machine: {machine} Application Domain: {appDomain} Process Id: {processId} Process Name: {processName} Win32 Thread Id: {win32ThreadId} Thread Name: {threadName} Extended Properties: {dictionary({key} - {value} )}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Text Formatter"/>

</formatters>

<categorySources>

<add switchValue="All" name="General">

<listeners>

<add name="Database Trace Listener"/>

</listeners>

</add>

</categorySources>

<specialSources>

<allEvents switchValue="All" name="All Events"/>

<notProcessed switchValue="All" name="Unprocessed Category"/>

<errors switchValue="All" name="Logging Errors &amp; Warnings">

<listeners>

<add name="Database Trace Listener"/>

</listeners>

</errors>

</specialSources>

</loggingConfiguration>

<exceptionHandling>

<exceptionPolicies>

<add name="General Policy">

<exceptionTypes>

<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow" name="Exception">

<exceptionHandlers>

<add logCategory="General" event severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Logging Handler"/>

</exceptionHandlers>

</add>

</exceptionTypes>

</add>

</exceptionPolicies>

</exceptionHandling>

<connectionStrings>

<!--<add name="ORE" connectionString="data source=TEST-SERVER-DATA;Integrated Security=SSPI;Database=SSET_US_P25;" providerName="System.Data.SqlClient"/>-->

<add name="ORE" connectionString="data source=CARLO-PC;Integrated Security=SSPI;Database=SSET_US_P25;" providerName="System.Data.SqlClient"/>

</connectionStrings>

<ore>

<data defaultProvider="SqlDataProvider">

<providers>

<clear/>

<add name="SqlDataProvider" type="ORE.Data.SqlDataProvider, ORE.SqlDataProvider" connectionStringName="ORE" upgradeConnectionString="" providerPath="~\Providers\DataProviders\SqlDataProvider\" objectQualifier="oq_" databaseOwner="dbo"/>

</providers>

</data>

<scheduling defaultProvider="MSScheduler">

<providers>

<clear/>

<add name="MSScheduler" type="ORE.Services.Scheduling.MSScheduling.MSScheduler, ORE.Services.Scheduling" providerPath="~\Providers\MSScheduler\" debug="false" maxThreads="1"/>

</providers>

</scheduling>

</ore>

<ore.SiebelWrite defaultProvider="SqlNetTiersProvider">

<providers>

<add name="SqlNetTiersProvider" type="ORE.SiebelWrite.DataAccess.SqlClient.SqlNetTiersProvider, ORE.SiebelWrite.DataAccess.SqlClient" connectionStringName="ORE" providerInvariantName="System.Data.SqlClient" entityFactoryType="ORE.SiebelWrite.Entities.EntityFactory" useEntityFactory="true" enableEntityTracking="true" enableMethodAuthorization="true" useStoredProcedure="false" defaultCommandTimeout="30"/>

</providers>

</ore.SiebelWrite>

<appSettings><add key="scon" value="server=localhost;database=Northwind;u/></appSettings>

<!--访问Web.config文件你可以通过使用ConfigurationSettings.AppSettings 静态字符串集合来访问 Web.config 文件示例

protected static string Isdebug = ConfigurationManager.AppSettings["scon"]-->

<appSettings>

<!--appSettings此节用于定义应用程序设置项。对一些不确定设置,还可以让用户根据自己实际情况自己设置-->

<add key="Conntction" value="server=192.168.85.66;user/> & lt;!--定义了一个连接字符串常量,并且在实际应用时可以修改连接字符串,不用修改程式代码-->.

<add key="ErrPage" value="Error.aspx"/><!--定义了一个错误重定向页面-->

<!--<add key="SiebelUrl" value="https://swsiis2.parttest.extranettest.microsoft.com"/>-->

<!--<add key="SiebelUrl" value="https://mssws.partners.extranet.microsoft.com"/>-->

<add key="SiebelUrl" value="https://msswspreprod.partners.extranet.microsoft.com"/>

<add key="ViewOppInSiebelLink" value="https://siebelpreprod.partners.extranet.microsoft.com/sales_enu/start.swe?SWECmd=GotoView&amp;SWEView=Opportunity+List+View&amp;SWERF=1&amp;SWEBU=1&amp;SWEApplet0=Opportunity+List+Applet&amp;SWERowId0="/>

<add key="ViewAccountInSiebelLink" value="https://siebelpreprod.partners.extranet.microsoft.com/sales_enu/start.swe?SWECmd=GotoView&amp;SWEView=Account+List+View&amp;SWERF=1&amp;SWEBU=1&amp;SWEApplet0=Account+List+Applet&amp;SWERowId0="/>

<add key="UsCustomerDocStore" value="http://usprofiling1:100/CustomerDocStore/default.aspx"/>

<add key="Deployment" value="UAT"/>

<add key="CutOffDate" value="2007/1/1"/>

<add key="TestTeam" value="hoptjw.w-ojrps.w-{oofq.w-jmhopi.w-yzoobe.w-ymobut.w-pbhnbt.w-fitjz.w"/>

<add key="Webserver" value="http://test-server-app:8020"/>

<add key="applicationName" value="{0} Opportunity Resource Engine"/>

<add key="applicationNameShort" value="{0} ORE"/>

<add key="IntroFile" value="D:\inetpub\ORE SE\documents\Intro.htm"/>

<add key="TestServer" value="True"/>

<!--Switch to specify whether an admin user should be notified about unhandled exceptions via email (true/false)-->

<add key="enableErrorNotification" value="true"/>

<!--Email addresses used for error notification-->

<add key="errorMessageFromEmailAddress" value="SSET US&lt;sset@microsoft.com&gt;"/>

<!--The email address(es) to appear in the To field. Separate with semicolons.-->

<add key="errorMessageToEmailAddresses" value="i-paalex@microsoft.com"/>

<!--Specifies the BCC address(es) for new opportunity requests (if any).If specifiying multiple addresses, separate with semicolons.-->

<add key="newRequestBCCEmailAddresses" value=""/>

<!--The default site coordinator details.These details will be used if a coordinator hasn't been selected from the list of Specialists.-->

<add key="defaultCoordinatorName" value="ORE Helpdesk"/>

<add key="defaultCoordinatorAlias" value="Help4US"/>

<add key="NotifierEmailAddress" value="ore@microsoft.com"/>

<!--Siebel location search filter-->

<add key="swsMSLocationFilter" value="United States"/>

<!--Specifies whether wildcards (*) are implicit in the Siebel Search (true/false)-->

<add key="useImplicitWildcards" value="False"/>

<!--If using implicit wildcards, specifies whether to prepend the wildcard to the search criterion (true/false)-->

<add key="addLeadingWildcard" value="False"/>

<!--Specifies whether to raise an error if the search returns 100 results (true/false)-->

<add key="raiseErrorIfExcessResults" value="True"/>

<!-- Specifies the default number of days to add to todays date in order to calulate the Request Due Date for a new request-->

<add key="defaultDueDateDaysToAdd" value="7"/>

<!-- Specifies the SMTP Server to use when sending emails-->

<add key="smtpServer" value="smtphost.redmond.corp.microsoft.com"/>

<!--The following key defines the list of acceptable character codes that should NOT be encoded by the IOSec.HtmlEncode method-->

<add key="allowedCharacterCodes" value="148,153,132,142,129,154,225,33,35,36,37,38,40,41,43,44,45,46,47,58,59,61,63,92,8211"/>

<!-- Database Settings for Siebel Upload-->

<add key="DatabaseServerUpload" value="test-server-data"/>

<add key="DatabaseCatalogUpload" value="SSET_US_P25"/>

<add key="DatabasePersistSecurityInfoUpload" value="false"/>

<!-- Version: Dev | Live | Config -->

<add key="Version" value="Dev"/>

<add key="NotificationFilter" value="pi{id.w-jfm{.w-ofitz.w-vidze.w-fitjz.w-hoptjw.w-ymobut.w-ojrps.w-{oofq.w-pbhfm.w-jmhopi.w-yzoobe.w"/>

<add key="LocalPort" value="10079"/>

<add key="RemotePort" value="10086"/>

<add key="AppointmentPage" value="CreateAppointment.aspx"/>

</appSettings>

<!--<system.Web>节,控制asp.net运行时的行为-->

<system.web>

<httpHandlers>

<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>

</httpHandlers>

<pages validateRequest="false" enableViewStateMac="true" enableEventValidation="false">

<controls>

<add tagPrefix="data" namespace="ORE.SiebelWrite.Web.Data" assembly="ORE.SiebelWrite.Web"/>

<add tagPrefix="data" namespace="ORE.SiebelWrite.Web.UI" assembly="ORE.SiebelWrite.Web"/>

</controls>

</pages>

<httpModules>

<add name="SiebelWriteEntityTransactionModule" type="ORE.SiebelWrite.Web.Data.EntityTransactionModule"/>

</httpModules>

<!--<compilation>节作用:配置 asp.NET 使用的所有编译设置。默认的debug属性为“True”.在程序编译完成交付使用之后应将其设为False-->

<compilation debug="true" defaultLanguage="c#">

<!--default language: 定义后台代码语言,可以选择c#和vb.net两种语言

debug : 为true时,启动aspx调试;为false不启动aspx调试,因而可以提高应用程序运行时的性能。一般程序员在开发时设置为true,交给客户时设置为false.

-->

<assemblies>

<add assembly="System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="Xceed.Compression.Formats, Version=1.0.5357.0, Culture=neutral, PublicKeyToken=BA83FF368B7563C6"/>

<add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="Xceed.Compression, Version=2.3.5357.0, Culture=neutral, PublicKeyToken=BA83FF368B7563C6"/>

<add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="Microsoft.ApplicationBlocks.Data, Version=1.8.0.0, Culture=neutral, PublicKeyToken=BB47406E8B145095"/>

<add assembly="Microsoft.Web.Services2, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

<add assembly="System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Xml, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Web.Services, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.Configuration.Install, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.Security, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.ServiceProcess, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="MS.Alchemy.CommonPlatform, Version=1.8.0.0, Culture=neutral, PublicKeyToken=BB47406E8B145095"/>

<add assembly="MS.Alchemy.Core, Version=1.8.0.0, Culture=neutral, PublicKeyToken=BB47406E8B145095"/>

<add assembly="MS.Alchemy.GlobalStore, Version=1.8.0.0, Culture=neutral, PublicKeyToken=BB47406E8B145095"/>

<add assembly="MS.Alchemy.LocalStore, Version=1.8.0.0, Culture=neutral, PublicKeyToken=BB47406E8B145095"/>

<add assembly="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>

</assemblies>

<buildProviders>

<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

</buildProviders>

</compilation>

<!--mode : 具有On,Off,RemoteOnly 3种状态。On表示始终显示自定义的信息; Off表示始终显示详细的asp.net错误信息; RemoteOnly表示只对不在本地Web服务器上运行的用户显示自定义信息.-->

<!--<customErrors> 为 asp.NET 应用程序提供有关自定义错误信息的信息。它不适用于 xml Web services 中发生的错误。-->

<customErrors mode="RemoteOnly" defaultRedirect="Error.aspx">

<error statusCode="440" redirect="err440.aspx"/>

<error statusCode="550" redirect="err550.aspx"/>

</customErrors>

<!--authentication 作用:配置 asp.NET 身份验证支持(为Windows、Forms、PassPort、None四种)。该元素只能在计算机、站点或应用程序级别声明。< authentication> 元素必需与<authorization> 节配合使用。-->

<!--<authentication mode="Windows"/>-->

<!--Windows: 使用IIS验证方式

Forms: 使用基于窗体的验证方式

Passport: 采用Passport cookie验证模式

None: 不采用任何验证方式-->

<authentication mode="Forms">

<forms name=".ASPUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30" />

</authentication>

<!--.Name: 指定完成身份验证的Http cookie的名称.

LoginUrl: 如果未通过验证或超时后重定向的页面URL,一般为登录页面,让用户重新登录

Protection: 指定 cookie数据的保护方式.

可设置为: All None Encryption Validation四种保护方式

a. All表示加密数据,并进行有效性验证两种方式

b. None表示不保护Cookie.

c. Encryption表示对Cookie内容进行加密

d. validation表示对Cookie内容进行有效性验证

TimeOut: 指定Cookie的失效时间. 超时后要重新登录.-->

<!--<authorization> 节

作用:控制对 URL 资源的客户端访问(如允许匿名用户访问)。此元素可以在任何级别(计算机、站点、应用程序、子目录或页)上声明。必需与<authentication> 节配合使用。

示例:以下示例禁止匿名用户的访问

注:你可以使用user.identity.name来获取已经过验证的当前的用户名;

可以使用web.Security.FormsAuthentication.RedirectFromLoginPage方法将已验证的用户重定向到用户刚才请求的页面

-->

<authorization>

<deny users="?"/>

</authorization>

<!--asp.net 关于form认证的一般设置:

1: 在web.config中,加入form认证;

<authentication mode="Forms">

<forms name="auth" loginUrl="index.aspx" timeout="30"></forms>

</authentication>

<authorization>

<deny users="?" />

</authorization>

2: 如果有注册页面时还应该允许匿名用户调用注册页面进行注册;

以下代码应该在<configuration><system.web>之间,而不应该包含到<system.web>..</system.web>之间;

----------------表示允许匿名用户对 userReg.aspx页面进行访问.

<location path="userReg.aspx">

<system.web>

<authorization>

<allow users="?" />

</authorization>

</system.web>

</location>

3 在登录成功后要创建身份验证票, 表明已经通过认证的合法用户;

if(登陆成功)

System.Web.Security.FormsAuthentication.SetAuthCookie(用户名称, false);-->

<!--<identity impersonate="true" userName="registry:HKLM\SOFTWARE\ORE\identity\ASPNET_SETREG,userName" password="registry:HKLM\SOFTWARE\ORE\identity\ASPNET_SETREG,password"/>-->

<!--<identity impersonate="true" userName="REDMOND\OREPP" password="@ct@BER_3RD"/>-->

<identity impersonate="true" userName="REDMOND\OREPP" password="nOvbEr_igtH"/>

<!--<trace> 配置 asp.NET 跟踪服务,主要用来程序测试判断哪里出错。

示例:以下为Web.config中的默认配置:

注:

enabled="false"表示不启用跟踪;

requestLimit="10"表示指定在服务器上存储的跟踪请求的数目

pageOutput="false"表示只能通过跟踪实用工具访问跟踪输出;

traceMode="SortByTime"表示以处理跟踪的顺序来显示跟踪信息

localOnly="true" 表示跟踪查看器 (trace.axd) 只用于宿主 Web 服务器

-->

<trace enabled="false" requestLimit="10" pageOutput="true" traceMode="SortByTime" localOnly="true"/>

<!--<sessionState> 为当前应用程序配置会话状态设置(如设置是否启用会话状态,会话状态保存位置)。-->

<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user cookieless="false" timeout="1440" />

<!--<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI" cookieless="false" timeout="1440"/>-->

<!--.mode: 分为off,Inproc,StateServer,SqlServer几种状态

mode = InProc 存储在进程中特点:具有最佳的性能,速度最快,但不能跨多台服务器存储共享.

mode = "StateServer" 存储在状态服务器中特点: 当需要跨服务器维护用户会话信息时,使用此方法。但是信息存储在状态服务器上,一旦状态服务器出现故障,信息将丢失

mode="SqlServer" 存储在sql server中特点:工作负载会变大,但信息不会丢失.

stateConnectionString : 设置将session信息存储在状态服务中时使用的服务器名称和端口号,默认是本机,当mode的值是StateServer是,这个属性是必需的。例如:"tcpip=127.0.0.1:42424”。

sqlConnectionString: 设置与sql server连接时的连接字符串。例如"data source= localhost;Integrated Security=SSPI;Initial Catalog=northwind"。当mode的值是 SQLServer时,这个属性是必需的

Cookieless:设置为true时,表示不使用cookie会话状态来标识客户;否则,相反.

TimeOut:用来定义会话状态存储的时间,超过期限,将自动终止会话.-->

<!--asp.NET中客户端session状态的存储

  常有的session模型中,session状态应该存储在两个地方,分别是客户端和服务器端。客户端只负责保存相应网站的SessionID,而其他的session信息则保存在服务器端。

在asp中,客户端的SessionID实际是以Cookie的形式存储的。如果用户在浏览器的设置中选择了禁用Cookie,那末他也就无法享受session的便利之处了,甚至造成不能访问某些网站。

为了解决以上问题,在 asp.NET中客户端的session信息存储方式分为:Cookie和Cookieless两种。

  asp.NET中,默认状态下,在客户端还是使用Cookie存储session信息的。如果我们想在客户端使用Cookieless的方式存储session信息的方法如下:

  找到当前Web应用程序的根目录,将cookieless="false"改为:cookieless="true",这样,客户端的session信息就不再使用 Cookie存储了,而是将其通过URL存储。

重新访问Web应用程序,就会看到类似下面的样子:其中,http://localhost/MyTestApplication/(ulqsek45heu3ic2a5zgdl245) /default.aspx中黑体标出的就是客户端的session ID。

注意,这段信息是由IIS自动加上的,不会影响以前正常的连接。-->

<!--

当mode的值是InProc时,说明服务器正在使用这种模式。

这种方式和以前asp中的模式一样,就是服务器 将session信息存储在IIS进程中。当IIS关闭、重起后,这些信息都会丢失。但是这种模式也有自己最大好处,就是性能最高。应为所有的 session信息都存储在了IIS的进程中,所以IIS能够很快的访问到这些信息,这种模式的性能比进程外存储session信息或是在sql server中存储session信息都要快上很多。这种模式也是asp.NET的默认方式。

将服务器session信息存储在进程外

(1)打开管理工具->服务,找到名为:asp.NET State Service的服务,启动它。实际上,这个服务就是启动一个要保存session信息的进程。启动这个服务后,你可以从Windows任务管理器 ->进程中看到一个名为 aspnet_state.exe的进程,这个就是我们保存session信息的进程。

(2)将mode的值改为StateServer。

   实际上,这种将session信息存储在进程外的方式不光指可以将信息存储在本机的进程外,还可以将session信息存储在其他的服务器的进程中。这 时,不光需要将mode的值改为StateServer,还需要在stateConnectionString中配置相应的参数。例如你的计算你是 192.168.0.1,你想把session存储在ip为192.168.0.2的计算机的进程中,就需要设置成这样: stateConnectionString="tcpip=192.168.0.2:42424"。当然,不要忘记在192.168.0.2的计算机中 装上.NET Framework,并且启动asp.NET State Services服务。

将服务器session信息存储在sql server中

(1)启动sql server和sql server代理服务。在sql server中执行一个叫做 InstallSqlState.sql的脚本文件。这个脚本文件将在sql server中创建一个用来专门存储session信息的数据库,及一个维护session信息数据库的sql server代理作业。

可以在以下路径中找到那个文件:

[system drive]\winnt\Microsoft.NET\Framework\[version]\

(2) 打开查询分析器,连接到sql server服务器,打开刚才的那个文件并且执行。稍等片刻,数据库及作业就建立好了。这时,可以打开企业管理器,看到新增了一个叫ASPState的数 据库。但是这个数据库中只是些存储过程,没有用户表。实际上session信息是存储在了tempdb 数据库的ASPStateTempSessions表中的,另外一个ASPStateTempApplications表存储了asp中 application对象信息。这两个表也是刚才的那个脚本建立的。另外查看管理->SQL server代理->作业,发现也多了一个叫做ASPState_Job_DeleteExpiredSessions的作业,这个作业实际上就是 每分钟去ASPStateTempSessions 表中删除过期的session信息的。

  接着,我们返回到Web.config文件,修改 mode的值改为SQLServer。注意,还要同时修改sqlConnectionString的值,格式 为:sqlConnectionString="data source=localhost; Integrated Security=SSPI;"

   其中data source是指sql server服务器的ip地址,如果sql server与IIS是一台机子,写127.0.0.1 就行了。Integrated Security=SSPI的意思是使用Windows集成身份验证,这样,访问数据库将以asp.NET的身份进行,通过如此配置,能够获得比使用 sql server验证方式更好的安全性。当然,如果sql server运行于另一台计算机上,你可能会需要通过Active Directory域的方式来维护两边验证的一致性。

-->

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US"/>

<!--requestEncoding: 它用来检查每一个发来请求的编码,responseEncoding: 用于检查发回的响应内容编码,fileEncoding: 用于检查aspx,asax等文件解析的默认编码-->

<!--<webServices>

<soapExtensionTypes>

<add type="Microsoft.Web.Services2.WebServicesExtension, Microsoft.Web.Services2, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" priority="1" group="0"/>

</soapExtensionTypes>

</webServices>-->

<!--<httpRuntime>配置 asp.NET HTTP 运行库设置。该节可以在计算机、站点、应用程序和子目录级别声明。-->

<!--Eg:控制用户上传文件最大为4M,最长时间为60秒,最多请求数为100-->

<httpRuntime maxRequestLength="4000" executionTimeout="60" appRequestQueueLimit="100"/>

<!--<httpRuntime executionTimeout="36000" useFullyQualifiedRedirectUrl="true" maxRequestLength="81920"/>-->

<!--<pages> 标识特定于页的配置设置(如是否启用会话状态、视图状态,是否检测用户的输入等)。可以在计算机、站点、应用程序和子目录级别声明。-->

<!-- 示例:不检测用户在浏览器输入的内容中是否存在潜在的危险数据(注:该项默认是检测,如果你使用了不检测,一定要对用户的输入进行编码或验证),在从客户 端回发页时将检查加密的视图状态,以验证视图状态是否已在客户端被篡改。(注:该项默认是不验证)-->

<pages validateRequest="false" buffer="true" enableViewStateMac="true" />

</system.web>

<!--特定应用程序配置 特点: 位于<appSetting>,可以定义应用程序的全局常量设置等信息-->

<system.runtime.remoting>

<application>

<client>

<wellknown type="ClientStore, LocalTransactionStore" url="http://localhost:8000/ClientStore.rem"/>

</client>

<channels>

<channel ref="http" port="0">

<clientProviders>

<formatter ref="binary"/>

</clientProviders>

</channel>

</channels>

</application>

</system.runtime.remoting>

<!--UAT-->

<ms.alchemy.commonplatform>

<runtime directory="C:\Program Files\Microsoft Alchemy\Common Platform 1.8\metadata" stsprimary="ACPSTS.partners.extranet.microsoft.com" autodelegate="true" clientname="6E8D3B96-5616-4899-834F-E26ED15F1A33" hostname="" instrumentationlevel="0" minimumcompressionpercent="10" maxdatasize="4000" mode="Native" proxyprocessor="Required" stssecondary="" tracelevel="5" transactionloglevel="Request|Response" ltsmachine="localhost" ltsport="8000" ltsmode="Remoting" serverprocessor="Required"/>

<cache transactions="120" consumer="36000" user="36000" entity="36000" config="30"/>

<lts frequency="60" tracing="On" gtsmachine="ACPGTS.partners.extranet.microsoft.com" gtsport="8989" samplerate="1" exceedfrequency="25" maxworkingset="35000"/>

</ms.alchemy.commonplatform>

<!--TEST-->

<!--<ms.alchemy.commonplatform>

<runtime directory="C:\Program Files\Microsoft Alchemy\Common Platform 1.8\metadata" stsprimary="juacpqa.parttest.extranettest.microsoft.com" autodelegate="true" clientname="oretsa_dec19test2" hostname="" instrumentationlevel="0" minimumcompressionpercent="10" maxdatasize="4000" mode="Native" proxyprocessor="Required" stssecondary="" tracelevel="5" transactionloglevel="Request|Response" ltsmachine="localhost" ltsport="8000" ltsmode="Remoting" serverprocessor="Required"/>

<cache transactions="120" consumer="36000" user="36000" entity="36000" config="30"/>

<lts frequency="60" tracing="On" gtsmachine="juacpqa.parttest.extranettest.microsoft.com" gtsport="8989" samplerate="1" exceedfrequency="25" maxworkingset="35000"/>

</ms.alchemy.commonplatform>-->

<!--PRODUCTION-->

<!--<ms.alchemy.commonplatform>

<runtime directory="C:\Program Files\Microsoft Alchemy\Common Platform 1.8\metadata" stsprimary="ACPSTS.partners.extranet.microsoft.com" autodelegate="true" clientname="09FCF9C4-546F-43C5-B1A2-4FE77A8BD0DC" hostname="" instrumentationlevel="0" minimumcompressionpercent="10" maxdatasize="4000" mode="Native" proxyprocessor="Required" stssecondary="" tracelevel="5" transactionloglevel="Request|Response" ltsmachine="localhost" ltsport="8000" ltsmode="Remoting" serverprocessor="Required"/>

<cache transactions="120" consumer="36000" user="36000" entity="36000" config="30"/>

<lts frequency="60" tracing="On" gtsmachine="ACPGTS.partners.extranet.microsoft.com" gtsport="8989" samplerate="1" exceedfrequency="25" maxworkingset="35000"/>

</ms.alchemy.commonplatform>-->

</configuration>