profile 元素(ASP.NET 设置架构)

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

使用 ASP.NET 配置文件来配置用于管理用户配置文件值的参数。

此元素是 .NET Framework 2.0 版中的新元素。

<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 特性。

指定默认配置文件提供程序的名称。

有关更多信息,请参见 Provider

默认值为 AspNetSqlProfileProvider。

inherits

可选的 String 特性。

包含从 ProfileBase 抽象类派生的自定义类型的类型引用。 ASP.NET 动态地生成一个从该类型继承的 ProfileCommon 类,并将该类放在当前 HttpContextProfile 属性中。

automaticSaveEnabled

可选的 Boolean 特性。

指定用户配置文件是否在 ASP.NET 页执行结束时自动保存。 如果为 true,则用户配置文件在 ASP.NET 页执行结束时自动保存。

只有在 ProfileModule 对象检测到某一用户配置文件已修改的情况下,该模块才保存该配置文件。 也就是在 IsDirty 属性为 true 的情况下。 有关更多信息,请参见 ASP.NET Profile Properties Overview

默认值为 true。

子元素

元素

说明

properties

必需的元素。

定义用户配置文件属性和属性组的集合。

providers

可选元素。

定义配置文件提供程序的集合。

父元素

元素

说明

configuration

指定公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中均需要的根元素。

system.web

为 ASP.NET 配置节指定根元素。

备注

有关访问和修改应用程序代码中 profile 元素的配置值的信息,请参见 ProfileSection

默认配置

下面的默认 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 文件以使用 SqlProfileProvider 提供程序。

<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

配置成员

SystemWebSectionGroup.Profile

可配置的位置

Machine.config

根级别的 Web.config

应用程序级别的 Web.config

要求

Microsoft Internet 信息服务 (IIS) 版本 5.0、5.1 或 6.0

.NET Framework 2.0 版

Microsoft Visual Studio 2005

请参见

任务

How to: Lock ASP.NET Configuration Settings

参考

system.web 元素(ASP.NET 设置架构)

<configuration> 元素

profile 的 properties 元素(ASP.NET 设置架构)

profile 的 providers 元素(ASP.NET 设置架构)

ProfileSection

System.Configuration

System.Web.Configuration

概念

ASP.NET Profile Properties Overview

ASP.NET Configuration Overview

ASP.NET Server Controls and Browser Capabilities

Securing Configuration

Configuration Inheritance

其他资源

ASP.NET Configuration Files

ASP.NET 配置设置

常规配置设置 (ASP.NET)

ASP.NET Configuration API