使用 ASP.NET 配置文件来配置用于管理用户配置文件值的参数。
此元素是 .NET Framework 2.0 版中的新元素。
??system.web 元素(ASP.NET 设置架构)
????profile 元素(ASP.NET 设置架构)
<profile
    enabled="true|false"
    inherits="fully qualified type reference"
    automaticSaveEnabled="true|false"
    defaultProvider="provider name">
    <properties>...</properties>
    <providers>...</providers>
</profile> | 
属性和元素
下面几部分描述了属性、子元素和父元素。
属性
| 属性 | 说明 | 
|---|---|
| 
               enabled  | 
            
               可选的 Boolean 属性。 指定是否启用 ASP.NET 用户配置文件。如果为 true,则启用 ASP.NET 用户配置文件。 默认值为 true。  | 
          
| 
               defaultProvider  | 
            
               可选的 String 属性。 指定默认配置文件提供程序的名称。 有关更多信息,请参见  默认值为 AspNetSqlProfileProvider。  | 
          
| 
               inherits  | 
            
               可选的 String 属性。 包含从   | 
          
| 
               automaticSaveEnabled  | 
            
               可选的 Boolean 属性。 指定用户配置文件是否在 ASP.NET 页执行结束时自动保存。如果为 true,则用户配置文件在 ASP.NET 页执行结束时自动保存。 只有在  默认值为 true。  | 
          
子元素
| 元素 | 说明 | 
|---|---|
| 
               properties  | 
            
               必选的元素。 定义用户配置文件属性和属性组的集合。  | 
          
| 
               providers  | 
            
               可选的元素。 定义配置文件提供程序的集合。  | 
          
父元素
| 元素 | 说明 | 
|---|---|
| 
               configuration  | 
            
               指定公共语言运行库和 .NET Framework 应用程序所使用的每个配置文件中均需要的根元素。  | 
          
| 
               system.web  | 
            
               为 ASP.NET 配置节指定根元素。  | 
          
备注
有关访问和修改应用程序代码中 profile 元素的配置值的信息,请参见 
默认配置
下面的默认 profile 元素在 .NET Framework 版本 2.0 的 Machine.config 文件中配置。
| ? |  复制代码 | 
|---|---|
<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> | |
示例
下面的代码示例演示如何配置 ASP.NET 应用程序的 Web.config 文件以使用 
| ? |  复制代码 | 
|---|---|
<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial 
         Catalog=aspnetdb;" />
  </connectionStrings>
  <system.web>
    <authentication mode="Forms" >
      <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
    <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
      <providers>
        <clear/>
        <add name="SqlProvider" 
             type="System.Web.Security.SqlMembershipProvider" 
             connectionStringName="SqlServices"
             applicationName="SampleApplication"
             enablePasswordRetrieval="true"
             enablePasswordReset="true"
             passwordFormat="Encrypted"
             requiresQuestionAndAnswer="true" />
      </providers>
    </membership>
    <profile defaultProvider="SqlProvider">
      <providers>
        <clear />
        <add name="SqlProvider"
             type="System.Web.Profile.SqlProfileProvider"
             connectionStringName="SqlServices"
             applicationName="SampleApplication"
             description="SqlProfileProvider for SampleApplication" />
      </providers>
      <properties>
        <add name="ZipCode" />
        <add name="CityAndState" />
      </properties>
    </profile>
  </system.web>
</configuration> | |
元素信息
| 
             配置节处理程序  | 
          
             System.Web.Configuration.ProfileSection  | 
        
| 
             配置成员  | 
          
             
                | 
        
| 
             可配置的位置  | 
          
             Machine.config 根级别的 Web.config 应用程序级别的 Web.config  | 
        
| 
             要求  | 
          
             Microsoft Internet 信息服务 (IIS) 版本 5.0、5.1 或 6.0 .NET Framework 2.0 版 Microsoft Visual Studio 2005  | 
        
请参见
任务
参考
system.web 元素(ASP.NET 设置架构)profile 的 properties 元素(ASP.NET 设置架构)
profile 的 providers 元素(ASP.NET 设置架构)
概念
其他资源
ASP.NET 配置设置
常规配置设置 (ASP.NET)