Asp.Net 2.0的匿名用户的Profile
来源:互联网 发布:淘宝周年庆 编辑:程序博客网 时间:2024/06/06 08:24
匿名用户也有Profile?答案是肯定的。前面说过,asp.net2.0加入了一个匿名跟踪机制,它可以产生一个独一无二的GUID识别码附加到未经过验证的网页的Request中。
默认的“匿名身份识别”是disabled,因此如果要想让你的网站识别匿名用户需要在Web.Config文件中进行如下配置:
<system.web>
<anonymousIdentification enabled="true"/ >
</system.web>
设置完毕就可以通过this.Request.AnonymousID取出用户的GUID。
使用匿名用户Profile的场境:
1) 过去做购物网站时,我们将购物车放在Session中,但Session有一定的过期策略,一般为20分钟。如果我们逛了半小时才进行结账的话,那购物车的数据通过Profile保存是最好的。
2) 有人逛购物网站并不喜欢登录后再购买,而时逛着逛着发现一个好东西,这里再去登录购买的话就会让用户感到有点烦,尤其在网络速度比较慢的情况下。这时可以使用匿名身份对用户购买的东西进行记录,在结账的时候再让用户输入账号密码,进行结账。
使用匿名Profile有两个关键点:
1) 将anonymousIdentification的enable属性设为true
2) 将相应匿名保存的Profile字段属性也设为allowAnonymous="true"
使用匿名Profile存储信息:
第一步:将anonymousIdentification的enable属性设为true
<anonymousIdentification enabled="true" cookieless="UseCookies"></anonymousIdentification>
第二步:在Web.Config文件中将“前景色”与“背景色”两个属性设为allowAnonymous="true"
<profile>
<properties>
<add name="name" type="System.String"></add>
<add name="age" type="System.Int32"></add>
<add name="school" type="System.String"></add>
<group name="color">
<add name="forecolor" type="System.Drawing.Color" serializeAs="Binary" allowAnonymous="true"></add>
<add name="backcolor" type="System.Drawing.Color" serializeAs="Binary" allowAnonymous="true"></add>
</group>
</properties>
<profile>
第三步:设置匿名用户的“前景色”和“背景色”
Profile.color.backcolor = Color.FromName(listBack.Text);
Profile.color.forecolor = Color.FromName(listFore.Text);
Label1.ForeColor = Profile.color.forecolor;
Label1.BackColor = Profile.color.backcolor;
第四步:查看aspnet_profile表中的内容,发现颜色被存进表中了。
匿名者的Profile向登录用户的迁移(Migration)
第一步:如上
第二步:如上
第三步:如上
第四步:在网站的Global.asax中添加下列代码:
void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs args)
{
//取得匿名用户的ID
ProfileCommon anonyProfile = Profile.GetProfile(args.AnonymousID);
if ((anonyProfile.color.backcolor != null) && (anonyProfile.color.forecolor != null))
{
Profile.color.forecolor = anonyProfile.color.forecolor;
Profile.color.backcolor = anonyProfile.color.backcolor;
Profile.Save();
}
//删除匿名用户的Profile
ProfileManager.DeleteProfile(args.AnonymousID);
//清除匿名用户的Cookie或身份资料
AnonymousIdentificationModule.ClearAnonymousIdentifier();
}
用户登录时就会引发Profile_MigrateAnonymous事件将匿名用户迁移到用户的Profile
- Asp.Net 2.0的匿名用户的Profile
- ASP.net 2.0 学习使用用户配置文件Profile对象(三)如何合并匿名用户配置文件Profile对象解决购物车的问题
- Asp.Net 2.0 的 Profile
- Asp.Net 2.0的Profile
- Asp.net用户个性化配置(Profile)的使用要点
- Profile的介绍(asp.net 2.0)
- Profile的介绍(asp.net 2.0)
- 实现Profile购物车的匿名用户迁移
- 实现Profile购物车的匿名用户迁移
- 实现Profile购物车的匿名用户迁移
- ASP.NET - 如何:向匿名用户和登录用户显示不同的信息
- ASP.NET 2.0 Profile和Session的对比
- asp.net 2.0 Profile 的一些注意事项(序列化)
- 考察ASP.NET 2.0的Membership, Roles,Profile - Part 6
- 考察ASP.NET 2.0的Membership, Roles,Profile - Part 8
- asp.net 2.0 自定义 基于 Table 的 Profile Provide
- 考察ASP.NET 2.0的Membership, Roles,Profile
- 考察ASP.NET 2.0的Membership, Roles和Profile
- n个数所有全排算法,通用
- 数据库查询
- 学习网站
- 调试时出现若要调试此模块,请将其项目生成配置更改为“调试”模式
- win7休眠自动启动 作者:Lee 日期:2010-07-26
- Asp.Net 2.0的匿名用户的Profile
- ZOJ 1649 Rescue
- Spring AOP+ehCache简单缓存系统解决方案
- 袁崇焕
- 无题
- dojo.data学习
- 关于VB.NET的事件(event)(一)
- 【对于单链表复制错误的反思】
- org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'taglib'. 异常