惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
C
Check Point Blog
Vercel News
Vercel News
Y
Y Combinator Blog
G
Google Developers Blog
P
Proofpoint News Feed
WordPress大学
WordPress大学
MongoDB | Blog
MongoDB | Blog
博客园 - 司徒正美
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
L
LangChain Blog
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
博客园_首页
B
Blog RSS Feed
The Cloudflare Blog
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog

博客园 - 头发乱了

关于在VistaIIS7中用VS2005调试Web项目 ASP.NET中的状态管理(转载) ADO.NET中实现事务处理 - 头发乱了 - 博客园 ASP.NET网站建设基本常用代码 - 头发乱了 - 博客园 父窗口与子窗口交互 制作Javascript弹出窗口技巧九则 WebPart(汇总) 实现WebPart通信功能 实现WebPart管理功能 实现WebPart编辑功能 创建自定义的WebPart 创建一个简单的WebPart应用示例 Web部件概述 从 ProfileBase 类继承 - 头发乱了 注册用户实现购物车功能 匿名用户开启个性化设置 - 头发乱了 - 博客园 web.config配置文件示例(转载) SqlServer数据库配置 个性化用户配置(汇总)
购物车(实现匿名用户向注册用户迁移)
头发乱了 · 2006-10-25 · via 博客园 - 头发乱了

    在电子商务网站,用户大多喜欢匿名浏览商品,部分用户可能会选择一些商品直到结帐时候才登陆以确认身份,也就是说应用程序需要实现匿名用户的数据迁移到经过身份验证的注册用户。
    通过ProfileModule.MigrateAnonymous 事件可以完成这个功能。 
    当匿名使用应用程序的用户登录时,可以使用 MigrateAnonymous 事件将配置文件属性值从匿名配置文件中复制到已验证身份的配置文件中。
在启动启用了用户配置文件的应用程序时,ASP.NET 会创建一个类型为 ProfileCommon 的新类,该类从 ProfileBase 类继承。强类型访问器被添加到 profile 配置节中为每个属性定义的 ProfileCommon 类中。GetProfile 方法使您能够根据用户名检索 ProfileCommon 对象。可以使用当前经过身份验证的配置文件的 GetProfile 方法来检索匿名配置文件的属性值。然后可以将匿名属性值复制到已验证身份的用户的当前配置文件中。
    ProfileModule.MigrateAnonymous 事件应用简单示例   

<configuration>
  
<system.web>
    
<authentication mode="Forms" >
      
<forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" />
    
</authentication>

    
<anonymousIdentification enabled="true" />

    
<profile enabled="true" defaultProvider="AspNetSqlProvider">
      
<properties>
        
<add name="ZipCode" allowAnonymous="true" />
        
<add name="CityAndState" allowAnonymous="true" />
        
<add name="StockSymbols" type="System.Collections.ArrayList" allowAnonymous="true" />
      
</properties>
    
</profile>
  
</system.web>
</configuration>

    下面的代码示例演示 ASP.NET 应用程序的 Global.asax 文件中包含的 MigrateAnonymous 事件。MigrateAnonymous 事件将配置文件属性值从匿名配置文件复制到当前用户的配置文件。

public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
{
  ProfileCommon anonymousProfile 
= Profile.GetProfile(args.AnonymousID);

  Profile.ZipCode 
= anonymousProfile.ZipCode;
  Profile.CityAndState 
= anonymousProfile.CityAndState;
  Profile.StockSymbols 
= anonymousProfile.StockSymbols;

  
////////
  // Delete the anonymous profile. If the anonymous ID is not 
  
// needed in the rest of the site, remove the anonymous cookie.

  ProfileManager.DeleteProfile(args.AnonymousID);
  AnonymousIdentificationModule.ClearAnonymousIdentifier(); 
}


   

改进的购物车:

Web.config

Global.asax

代码下载
代码出自《asp.net2.0开发指南》。