ASP.NET 2.0(C#)(7) - Profile(存储用户配置)2011-12-31 webabcd 介绍ASP.NET 2.0 中的存储用户配置功能使您可以定义并存储要在整个应用程序中使用的基于用户的设置。而且,在用户未登录时,可以将这些设置存储在匿名配置文件中,然后在将来某个时间将其迁移到登录用户的配置文件中。关键1、配置<system.web>元素下的<profile>元素;如果需要支持匿名的话则还需要配置<system.web>元素下的<anonymousIdentification>元素。示例如下,仅为说明
<profile enabled="true" defaultProvider="SqlProfileProvider" inherits="CustomProfile"> <providers> <add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="SqlConnectionString" applicationName="/" /> </providers> <properties> <add name="Name" /> <add name="Color" type="System.Drawing.Color" /> <group name="Group"> <add name="Collection" type="System.Collections.ArrayList" /> <add name="Price" type="int" defaultValue="100" /> </group> </properties> </profile> <anonymousIdentification enabled="true" cookieName=".VS2005_ANONYMOUS" cookieTimeout="1440" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" cookieless="UseCookies" />
各属性详细说明参看MSDN,索引处查找“profile 元素”和“anonymousIdentification 元素”