asp.net 2.0 Profile 的一些注意事项(序列化)

    技术2022-05-11  86

    近日开发培训系统时,大量地使用到了 asp.net 2.0  的 profile 这个好用东西 配置文件是这样写          < profile defaultProvider = " MyProfileProvider "  automaticSaveEnabled = " false " >              <!-- 定义配置(profile) -->              < providers >                  < add name = " MyProfileProvider "  type = " System.Web.Profile.SqlProfileProvider "  applicationName = " CX "  connectionStringName = " CX.Services.CnString " />              </ providers >              < properties >                  < add name = " UserSelectorGlobalVar "  type = " Profiles.UserSelectorGlobalVar "   allowAnonymous = " false " ></ add >                  < add name = " UserExamDataSource "  type = " Profiles.UserExamDataSource "  allowAnonymous = " false " ></ add >                  < add name = " ExamSelectedTimu "  type = " Profiles.ExamSelectedTimu "  allowAnonymous = " false " ></ add >              </ properties >          </ profile > 其中有一个类的代码如下: using  System; using  System.Collections.Generic; using  System.Text; namespace  Profiles {        public class UserSelectorGlobalVar    {        public UserSelectorGlobalVar()        {        }        private static System.Collections.Generic.Dictionary<Guid, Models.UserInfo> _SelectedUsers             = new System.Collections.Generic.Dictionary<Guid, Models.UserInfo>();        public Dictionary<Guid, Models.UserInfo> SelectedUsers        {            get return _SelectedUsers; }            set { _SelectedUsers = value; }        }    }} 呵呵,但是当调用this.profile.Save () 的时候说这个类出错,我想是没有将这个类标志为可以序列化的,于是加上属性 [Serializable]但是问题依旧.后来想起以前做的一个实验中将一个IList<XXX> 序列化后存入一个文件,选用SOAP那种方式就出错,好像是不支持吧,改用Binary 那种方式就好了. 但是profile 的序列化方式在哪里设定呢后来想一下因该是在Web.Config 里面改的,借助VS2005 的代码提示功能发现   < add name = " ExamSelectedTimu "  type = " Profiles.ExamSelectedTimu "  allowAnonymous = " false " ></ add >这一句有一个属性:serializeAs 字面意思就能猜到啦,于是改为这样:<add name="ExamSelectedTimu" type="Profiles.ExamSelectedTimu" serializeAs="Binary" allowAnonymous="false"></add>Debug.... OK

    最新回复(0)