国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET2.0學習7--個性化用戶配置

2024-07-10 13:08:49
字體:
來源:轉載
供稿:網友

個性化用戶配置

一、簡介

為用戶提供自定義的外觀、內容、布局,當用戶再次訪問的時候,用戶還能看到自己原來的設定。

二、個性化的三大步驟

1.  識別用戶身份

要建立驗證用戶身份的機制

創建識別用戶需求的機制

創建管理用戶的機制

2.  提供個性化服務

針對注冊和匿名用戶提供不同的服務

3.  存貯用戶信息

可以保存用戶的相關信息,以方便下次使用,包括用戶的登陸信息

三、實現個性化服務的三大功能

1.  個性化用戶配置

2.  web部件

3.  成員和角色管理

四、為匿名用戶進行個性化設置

web.config配置

    <anonymousidentification enabled="true"/>

    <profile>

      <properties>

        <add name="name" allowanonymous="true" />

        <add name="lastsubmit" type="system.datetime" allowanonymous="true"/>

        <group name="address">

          <add name="city"  allowanonymous="true"/>

          <add name="postalcode"  allowanonymous="true"/>

        </group>

      </properties>

</profile>

代碼:

    protected void page_load(object sender, eventargs e)

    {

        if (!page.ispostback)

        {

            //顯示用戶配置信息

            displayprofileinfo();

        }

    }

    protected void btnsubmit_click(object sender, eventargs e)

    {

        //保存用戶配置信息到profile屬性中

        profile.name = txtname.text;

        profile.address.city = txtcity.text;

        profile.address.postalcode = txtpostalcode.text;

        profile.lastsubmit = datetime.now;

        //顯示用戶配置信息

        displayprofileinfo();

    }

    private void displayprofileinfo()

    {

        //從profile屬性中獲取數據并賦值給服務器控件           

        txtname.text = profile.name;

        txtcity.text = profile.address.city;

        txtpostalcode.text = profile.address.postalcode;

        datetime time = profile.lastsubmit;

        //如果未獲取值則顯示空,否則顯示獲取的值

        if (time.year == 1)

        {

            lablastsubmit.text = "空";

        }

        else

        {

            lablastsubmit.text = time.tostring();

        }

    }

五、為注冊用戶實現個性化用戶配置

web.config配置

    <connectionstrings>

        <add name="northwindconnectionstring" connectionstring="data source=localhost;initial catalog=northwind;integrated security=true"

            providername="system.data.sqlclient" />

    </connectionstrings>

    <system.web>        

          <profile>

              <properties>

                   <add name="shoppingcart" type="shoppingcart" serializeas="binary"/>

              </properties>           

          </profile>

          <authorization>

              <deny users="?"/>

          </authorization>

          <authentication mode="forms">

              <forms loginurl ="login.aspx"></forms>

          </authentication>

代碼示例:code 13-2

六、匿名用戶轉化為注冊用戶的處理

global.asax中的設置

    void profile_migrateanonymous(object sender, profilemigrateeventargs pe)

    {

        //獲取匿名用戶的profile對象

        profilecommon anonprofile = profile.getprofile(pe.anonymousid);

        //如果總價為不為0(說明匿名用戶進行了選擇),則將匿名用戶的profile存儲起來

        if (anonprofile.shoppingcart.total  != 0)

        {           

            profile.shoppingcart = anonprofile.shoppingcart;           

        }       

        //刪除匿名用戶的用戶數據(從aspnet_users表)

        membership.deleteuser(pe.anonymousid);

        //刪除匿名用戶的profle數據(從aspnet_profile表)

        profilemanager.deleteprofile(pe.anonymousid);

        //刪除匿名用戶標識

        anonymousidentificationmodule.clearanonymousidentifier();       

}

       示例代碼:code 13-3

七、刪除個性化信息

刪除匿名用戶的個性化信息

profilemanager.deleteprofile(context.request.anonymousid)

刪除注冊用戶的個性化信息

profilemanager.deleteprofile(user.identity.name)



收集最實用的網頁特效代碼!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 深泽县| 明星| 华阴市| 喀喇| 安平县| 台北县| 阳曲县| 宝应县| 抚顺市| 霸州市| 福海县| 南宁市| 乌海市| 邻水| 新绛县| 汝阳县| 临潭县| 汉沽区| 泰宁县| 个旧市| 潮州市| 遵义县| 安多县| 武隆县| 蒲江县| 夏津县| 邹城市| 宁津县| 乾安县| 辽阳市| 建水县| 大庆市| 贡觉县| 大庆市| 鹤山市| 塘沽区| 黎平县| 吉水县| 长葛市| 冀州市| 密云县|