Profile及成员资料管理二

本文深入探讨了ASP.NET配置文件中Profile节点的解析过程,详细介绍了如何通过配置文件实现Profile的运行机制,包括自动保存设置、默认提供者选择及不同属性配置的用途。同时解释了Profile节点中提供的不同属性及其类型,如ShoppingCart、WishList和AccountInfo,以及这些属性是如何通过配置文件与PetShopProfileProvider类进行交互的。

今天网上找关于Profile的资料,欣喜的发现Profile的处理机制了。

在上节中我叙述了Profile.PetShopProfleProvider的相关机制。但这个实现是很普通的,根本就没有有涉及到Profile的运行机制。

关键还是在web.config这个配置文件上,其实我也猜到了,猜到了ASP.NET运行的时候回去加载这个配置文件,然后去实现些什么。

但关键我不知道ASP.NET在这期间到底做了什么,现在知道了,具体就是这样的:

ASP.NET加载的时候呢找到了web.config这个配置文件,不言而喻就是找了了下面这个节点啦:

<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>

先来说明下这个节点吧:从properties属性可以看出设定了三个的属性是ShopingCart、WishList和AccountInfo,他们的类型都是BLL.Cart,它们的属性分别定义了ShoppingCartProvider、WishListProvider、AccountInfoProvider,它们的类型均为PetShop.Profile.PetShopProfileProvider类型。

那么它们的providers到底怎么调用呢?这个provider有何作用呢?待续。

ASP.NET解析了配置文件后,就实例化了ProfileCommon类,这个类事继承子ProfileBase类的,所以才有save()等方法啦。还有些是否匿名登录等等。然后呢,ASP.NET将创建好的ProfileCommon实例设置为页面的Profile属性值。感觉这句话怪怪的,我之前的理解应该是直接创建一个Profile的ProfileCommon对象。

但在msdn中找到的解释跟上面一样。

 

接下来就是我们定义的Profile.PetShopProfileProvider这个类是怎样被调用的了,在web.config中我们可以看到:defaultProvider="ShoppingCartProvider“

那么他会先找到ShoppingCartProvider,对于ShoppingCartProvider我们定义了他的类型还有数据库的连接字符串。这样不就可以自动连接数据库和实现PetShopProfileProvider这个类了?但数据访问这个东东应该是交给了SQLHelper这个类来做的,那么Profile节点这个数据库连接字符的是不是多余了?

转载于:https://www.cnblogs.com/huaizuo/archive/2011/07/14/2106757.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值