首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

ASP.NET 2.0 Profile 功能:儲存使用者個人化設定(含匿名遷移)

     編輯:關於ASP.NET

Profile 讓開發者以聲明式方式定義使用者屬性,自動持久化至資料庫,支援匿名使用者設定並在登入後無縫遷移。

web.config 完整配置範例

<profile enabled="true" defaultProvider="SqlProfileProvider" inherits="CustomProfile">
  <providers>
    <add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider"
         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" />

進階用法

  • inherits="CustomProfile":繼承自訂 ProfileBase 子類別,獲得強型別存取(Profile.Name vs Profile.GetPropertyValue("Name"))。
  • 群組屬性(<group>)邏輯分組,存取時 Profile.Group.Price。
  • 匿名識別啟用後,未登入使用者亦有 Profile,登入時呼叫 Profile.MigrateAnonymous(oldAnonId) 合併資料。

屬性詳細說明請參閱 MSDN「profile 元素」與「anonymousIdentification 元素」。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved