ASP.NET 2.0個人化配置(profile)
為每個使用者儲存配置資訊
強型別 長期儲存 支援匿名使用者
定義配置( profile )
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<connectionStrings>
<add name="Northwind" connectionString="Server=localhost;Integrated Security=True;Database=Northwind" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<anonymousIdentification enabled="true" />
<profile> //定義配置(profile)
<properties>
<add name="Theme" allowAnonymous="true" />
<add name="LastVisit" type="System.DateTime" allowAnonymous="true" />
</properties>
</profile>
<!--
<webParts> //定義配置(webParts)
<personalization defaultProvider="AspNetSqlPersonalizationProvider"/>
</webParts>
-->
<!--
Set compilation debug="true" to insert debugging symbols into the compiled page.
Because this affects performance, set this value to true only during development.
-->
<compilation debug="true">
<expressionBuilders>
<add expressionPrefix="Version" type="VersionExpressionBuilder"/>
</expressionBuilders>
</compilation>
<!--
The <authentication> section enables configuration of the security authentication
mode used by ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration of what to do if/when an unhandled
error occurs during the execution of a request. Specifically, it enables developers
to configure html error pages to be displayed in place of a error stack trace.
-->
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<!--
<error statusCode="403" redirect="NoAccess.htm"/>
<error statusCode="404" redirect="FileNotFound.htm"/>
-->
</customErrors>
</system.web>
</configuration>
使用配置(profile)
//increment the current user's post cout
profile.posts = profile.posts+1;
// update the current user's last post date
profile.lastpost = datetime.now;
個人化資料將存入資料庫
介紹
Microsoft ASP.NET 2.0支援被稱為Profile的新對象,它可以自動在多個Web應用程式的訪問之間儲存使用者資訊。一個User Profile中可以儲存各種類型的資訊,這些資訊既可以是簡單的string和integer類型,也可以是複雜的自訂類型。例如,你可以儲存使用者的姓、購物籃、使用者屬性或網站使用方式統計。
本文中,你將學習如何在一個應用中定義user profile。我們也會向你示範如何配置使用不同provider的profile。最後,你將學習如何管理和產生user profile的報告。
User Profiles總攬
Profile 對象與Session對象十分相似,但是更好用一些。與Session相似的地方在於,Profile是相對於一個特定的使用者的,也就是說,每個Web應用程式的使用者都有他們自己的profile對象。與Session不同的是,Profile對象是持久對象。如果你向