petshop4.0中的Profile理解(匿名用户身份)

 当未经过登陆而在PetShop中浏览时,持有和使用的是匿名用户身份。这种用户身份的用户名是一个 GUID字符串。可以通过用户迁移方法的重载将匿名用户转变为审核用户,实际上是为匿名用户生成Profile和相应的Cookie,不过维持的状态保存在本地电脑,如果Cookie过期或者使用其它电脑就可能导致信息丢失。

当在petshop中check out之后,会跳转到SignIn.aspx进行登录,之后执行Global.asax中的方法,将匿名用户转变为审核用户,并在Profile表和Cart表中将匿名用户的信息转变为登陆用户的信息。

通过执行Global.asax中的ProfileManager.DeleteProfile(e.AnonymousID); 然后跳转到PetShop.Profile.PetShopProfileProvider中的以下方法:

 


 public override int DeleteProfiles(string[] usernames) {

   
int deleteCount = 0;

   
foreach(string user in usernames)
    
if(DeleteProfile(user))
     deleteCount
++;

   
return deleteCount;
  }
private static bool DeleteProfile(string username) {
           CheckUserName(username);
           
return dal.DeleteProfile(username, applicationName);            
}

 

执行PetShop.SQLProfileDAL.PetShopProfileProvider中的

 


        public bool DeleteProfile(string userName, string appName) {

            
int uniqueID = GetUniqueID(userName, falsetrue, appName);

            
string sqlDelete = "DELETE FROM Profiles WHERE UniqueID = @UniqueID;";
            SqlParameter param 
= new SqlParameter("@UniqueId", SqlDbType.Int, 4);
            param.Value 
= uniqueID;

            
int numDeleted = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringProfile, CommandType.Text, sqlDelete, param);

            
if(numDeleted <= 0)
                
return false;
            
else
                
return true;
        }

 

方法,删除匿名用户。

你可能感兴趣的:(profile)