<profile enabled="true" defaultProvider="SqlProfileProvider" inherits="CustomProfile">
<providers>
<add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="SqlConnectionString"
applicationName="/" />
</providers>
<properties>
<add name="Name" />
<add name="Color" type="System.Drawing.Color" />
<group name="Group">
<add name="Collection" type="System.Collections.ArrayList" />
<add name="Price" type="int" defaultValue="100" />
</group>
</properties>
</profile>
<anonymousIdentification
enabled="true"
cookieName=".VS2005_ANONYMOUS"
cookieTimeout="1440"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All"
cookieless="UseCookies" />
void Profile_ProfileAutoSaving(Object sender, ProfileAutoSaveEventArgs e)
{
if ((e.Context.Items["CancelProfileAutoSave"] != null) && ((bool)e.Context.Items["CancelProfileAutoSave"] == true))
e.ContinueWithProfileAutoSave = false;
}
protected void Page_Load(object sender, EventArgs e)

{
Context.Items["CancelProfileAutoSave"] = true;
}
void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs pe)
{
// 获得匿名配置
ProfileCommon anonProfile = Profile.GetProfile(pe.AnonymousID);
// 从匿名配置中取值并赋值给经过身份验证的配置
if (anonProfile.Color != System.Drawing.Color.Empty)
{
Profile.Color = anonProfile.Color;
}
// 从数据库中删除匿名配置
ProfileManager.DeleteProfile(pe.AnonymousID);
// 清除与某个会话关联的匿名 Cookie 或标识符
AnonymousIdentificationModule.ClearAnonymousIdentifier();
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Profile;

/**//// <summary>
/// CustomProfile 的摘要说明
/// </summary>
public class CustomProfile : ProfileBase

{
private string _customName;
public string CustomName
{
get
{ return _customName; }
set
{ _customName = value; }
}
private bool _customSex;
public bool CustomSex
{
get
{ return _customSex; }
set
{ _customSex = value; }
}
}
<profile enabled="true" defaultProvider="SqlProfileProvider" inherits="CustomProfile">
<providers>
<add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="SqlConnectionString"
applicationName="/" />
</providers>
<properties>
<add name="Name" />
<add name="Color" type="System.Drawing.Color" />
<group name="Group">
<add name="Collection" type="System.Collections.ArrayList" />
<add name="Price" type="int" defaultValue="100" />
</group>
</properties>
</profile>
<%
@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Test.aspx.cs"
Inherits="Profile_Test" Title="存储用户配置测试" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Label ID="lbl" runat="Server" />
</asp:Content>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Profile_Test : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)
{
// 一看就懂
Profile.Name = User.Identity.Name;
Profile.Color = System.Drawing.Color.AliceBlue;
Profile.Group.Collection.Clear();
Profile.Group.Collection.Add("冰棍");
Profile.Group.Collection.Add("瓜子");
Profile.Group.Price = 999999;
Profile.CustomName = User.Identity.Name;
Profile.CustomSex = true;


lbl.Text = "Name:" + Profile.Name + "<br />";
lbl.Text += "Color:" + Profile.Color.ToString() + "<br />";
foreach (string s in Profile.Group.Collection)
{
lbl.Text += "商品有:" + s + "<br />";
}
lbl.Text += "价格:" + Profile.Group.Price + "<br />";
lbl.Text += "自定义类名字:" + Profile.CustomName + "<br />";
lbl.Text += "自定义类姓名:" + Profile.CustomSex;
}
}
发表于 @ 2007年09月25日 00:17:00 | 评论( loading... ) | 举报| 收藏