摘要:作者Blog:http://blog.csdn.net/wangyihust/
对于Microsoft .net PetShop程序中的购物车和订单处理模块,文中主要分析两种技术的应用:
1. Profile技术在PetShop程序中用于三处:
1) 购物车ShoppingCart -下面的例子围绕购物车流程进行
2) 收藏WishList
3) 用户信息AccountInfo
注册新用户 NewUser.aspx :使用的是CreateUserWizard 控件,基于MemberShip机制,在数据库MSPetShop4Services的表aspnet_Users中创建用户
修改用户注册信息 UserProfile.aspx: 基于Profile技术,在数据库MSPetShop4Profile的表Profiles和Account中创建用户信息
2. 异步消息处理技术运用于订单处理
4.1 Web.config配置
Profile可以利用数据库存储关于用户的个性化信息,有点象session对象,但session对象是有生存期的,在生存期后,session对象自动失效了。而profile不同,除非显式移除它。要实现profile功能,必须先在web.config中进行定义。
在web.congfig中,将会定义一些属性/值,分别存贮将要保存的变量和值,比如language属性,定义其值是string类型,如此类推。而<group>标签,则是将一些相同或类似功能的变量值放在一起。
程序中使用方法:Profile.language = ddlLanguage.SelectedItem.Value;
<profile automaticSaveEnabled="false" defaultProvider="ShoppingCartProvider">
<providers>
<add name="ShoppingCartProvider" connectionStringName="SQLProfileConnString" type="PetShop.Profile.PetShopProfileProvider" applicationName=".NET Pet Shop 4.0"/>
<add name="WishListProvider" connectionStringName="SQLProfileConnString" type="PetShop.Profile.PetShopProfileProvider" applicationName=".NET Pet Shop 4.0"/>
<add name="AccountInfoProvider" connectionStringName="SQLProfileConnString" type="PetShop.Profile.PetShopProfileProvider" applicationName=".NET Pet Shop 4.0"/>
</providers>
<properties>
<add name="ShoppingCart" type="PetShop.BLL.Cart" allowAnonymous="true" provider="ShoppingCartProvider"/>
<add name="WishList" type="PetShop.BLL.Cart" allowAnonymous="true" provider="WishListProvider"/>
<add name="AccountInfo" type="PetShop.Model.AddressInfo" allowAnonymous="false" provider="AccountInfoProvider"/>
</properties>
</profile>
4.2 购物车程序流程-Profile技术
1. 点击“加入购物车”: http://localhost:2327/Web/ShoppingCart.aspx?addItem=EST-34
2. ShoppingCart.aspx文件处理:在init方法之前处理
protected void Page_PreInit(object sender, EventArgs e) {
if (!IsPostBack) {
string itemId = Request.QueryString["addItem"];
if (!string.IsNullOrEmpty(itemId)) {
Profile.ShoppingCart.Add(itemId); //注意ShoppingCart的类型是PetShop.BLL.Cart
//Save 方法将修改后的配置文件属性值写入到数据源,如ShoppingCart属性已经改变
Profile.Save();
//......[
阅读全文]