Profile及成员资料管理二

今天网上找关于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/p/2106757.html