下面的示例 Web.config 文件指定一个用户配置文件,该配置文件包含字符串类型的 ZipCode 属性和 StringCollection 类型的 RecentSearchList 属性。所生成的 Profile 将是每个指定属性的强类型访问器。有关用户配置文件的信息以及设置和读取用户配置文件属性的示例,请参见 ASP.NET 配置文件属性。
<configuration>
<connectionStrings>
<add name="SqlServices" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial
Catalog=aspnetdb;" />
</connectionStrings>
<system.web>
<anonymousIdentification enabled="true" />
<profile defaultProvider="SqlProvider" >
<providers>
<add
name="SqlProvider"
connectionStringName="SqlServices"
applicationName="HttpProfileBaseApplication"
type="System.Web.Profile.SqlProfileProvider" />
</providers>
<properties>
<add name="ZipCode" allowAnonymous="true" />
<add name="RecentSearchList"
type="System.Collections.Specialized.StringCollection"
serializeAs="Xml"
allowAnonymous="true" />
</properties>
</profile>
</system.web>
</configuration>