查过MSDN与google,没有答案
以下是重写
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {            string username = HttpContext.Current.Session["name"] == null ? (string)context["UserName"] : HttpContext.Current.Session["name"].ToString();
            bool isAuthenticated = (bool)context["IsAuthenticated"];
             //其他省略.....3个问题
1:我调试的时候(string)context["UserName"] 的值为 PC-200901171137\Administrator(计算机名\我系统用户名),当我正常运行的时候它显示是 类似 b0e427d8-f20c-4348-8b86-52bb16b7387d 为什么?2:如果我做一个购物车,只要是匿名登录,匿名用户一直 b0e427d8-f20c-4348-8b86-52bb16b7387d  ,所以只要我每次不登陆都可以看见购物车的商品,那么当我 登陆以后,删掉此匿名用户,当下次再匿名访问的时候,它就重新生成类似cb3102cb-3fce-40fb-a5ee-8dd89e8ca476! (string)context["UserName"]到底是怎样实现上面的没登陆一直是同一个匿名用户,而删掉后又重新生成一个匿名用户,它是怎么实现的?
3:Global.asax文件的void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e)到底是什么时候触发的?

解决方案 »

  1.   

    未指定 ICollection 中值的顺序,但它与由 Keys 方法返回的 ICollection 中的相关联键的顺序相同。返回的 ICollection 不是静态副本;相反,ICollection 反向引用原始 Hashtable 中的值。因此,对 Hashtable 的更改将继续反映到 ICollection 中。
    =============
    会不会有给这个值赋值的情况
      

  2.   

    或者在watch窗口中把全部的值都看下
      

  3.   

    这有什么好奇怪的...SettingsContext["UserName"]就是当前页面已验证身份的用户标识,你调试时是用Windows身份验证,部署时是ASP.NET Profile,匿名用户只有一个...去看MSDN,了解一下ASP.NET的身份验证和相关配置文件的知识...
      

  4.   

    第三个问题,我想问下,用forms认证,当我登录的时候,执行登录后执行了FormsAuthentication.SetAuthCookie(txtName .Text .Trim (),false );方法登录,然后就自动执行了Global.asax中Profile_MigrateAnonymous的方法实现匿名到非匿名用户间的转换,其实这个原来就是用了事件订阅机制  那么如果我用windows认证,当登录后要执行Global.asax中Profile_MigrateAnonymous的方法实现匿名到非匿名用户间的转换,要怎么做?
      

  5.   

    该事件在拥有用户配置的用户登录时触发。(Global.asax)
    public void Profile_OnMigrateAnonymous(object sender,ProfileMigrateEventArgs args)
    {
    //Get anonymous profile
    ProfileCommon anonProfile = Profile.GetProfile(args.AnonymousID);//Copy anonymous properties to authenticated
    foreach(SettingsProperty prop in ProfileBase.Properties)
    {
    Profile[prop.Name]=anonProfile[prop.Name];
    }//Kill the anonymous profile
    ProfileManager.DeleteProfile(args.AnonymousID);
    AnonymousIdentificationModule.ClearAnonymousIdentifier();
    }
    如果不销毁匿名标识,则MigrateAnonymous事件在登录验证后的每次页面请求都会被执行。