c# - asp.net User Profile: how do I add a field once the DB has Users? -
my app has been live time there many users in db , have profile data attached, need add field profile.
i added new field web.config file:
<add name="defaulttook" type="system.boolean" defaultvalue="true" />
i updated relevant classes , methods assign variable:
// registrationdata class ... [display(name = "defaulttooklabel", description = "defaulttookdescription", resourcetype = typeof(registrationdataresources))] public bool defaulttook { get; set; } ... public void getdatafrommembershipuser(membershipuser user) { webprofile profile = webprofile.getprofile(user.username); ... if (profile.defaulttook != null) this.defaulttook = profile.defaulttook; ... } // added elsewhere (user.cs, userregistrationservice.cs , userdata poco)
when try run , login, comes exception (understandably) field not found in profile data in db:
system.servicemodel.domainservices.client.domainoperationexception unhandled user code message=load operation failed query 'login'. profile property not exist defaultstook. innerexception message: settings property 'defaultstook' not found. errorcode=500 ...
my question is: how add new field asp_net profile without having exception thrown?
edit: web config
<profile defaultprovider="aspnetsqlprofileprovider" enabled="true"> <providers> <clear /> <add name="aspnetsqlprofileprovider" type="myapp.web.mysqlprofileprovider" connectionstringname="applicationservices" applicationname="/" /> </providers> <properties> <add name="friendlyname" /> <add name="jobtitle" /> <add name="toplevelviewname" defaultvalue="[any]" /> <add name="toplevelviewid" type="system.guid" defaultvalue="[null]" /> <add name="routeids" /> <add name="toplevelviewtype" type="system.int32" defaultvalue="0" /> <add name="passwordquestionanswer" /> <add name="criticality" type="system.int32" defaultvalue="0" /> <!-->add name="defaulttook" type="system.boolean" defaultvalue="true" /--> </properties> </profile>
web profile
public partial class webprofile { private system.web.profile.profilebase _profilebase; public webprofile() { this._profilebase = new system.web.profile.profilebase(); } public webprofile(system.web.profile.profilebase profilebase) { this._profilebase = profilebase; } public virtual string routeids { { return ((string)(this.getpropertyvalue("routeids"))); } set { this.setpropertyvalue("routeids", value); } } public virtual string passwordquestionanswer { { return ((string)(this.getpropertyvalue("passwordquestionanswer"))); } set { this.setpropertyvalue("passwordquestionanswer", value); } } public virtual string jobtitle { { return ((string)(this.getpropertyvalue("jobtitle"))); } set { this.setpropertyvalue("jobtitle", value); } } public virtual int toplevelviewtype { { return ((int)(this.getpropertyvalue("toplevelviewtype"))); } set { this.setpropertyvalue("toplevelviewtype", value); } } public virtual string friendlyname { { return ((string)(this.getpropertyvalue("friendlyname"))); } set { this.setpropertyvalue("friendlyname", value); } } public virtual string toplevelviewname { { return ((string)(this.getpropertyvalue("toplevelviewname"))); } set { this.setpropertyvalue("toplevelviewname", value); } } public virtual int criticality { { return ((int)(this.getpropertyvalue("criticality"))); } set { this.setpropertyvalue("criticality", value); } } public virtual system.guid toplevelviewid { { return ((system.guid)(this.getpropertyvalue("toplevelviewid"))); } set { this.setpropertyvalue("toplevelviewid", value); } } public static webprofile current { { return new webprofile(system.web.httpcontext.current.profile); } } public virtual system.web.profile.profilebase profilebase { { return this._profilebase; } } public virtual object this[string propertyname] { { return this._profilebase[propertyname]; } set { this._profilebase[propertyname] = value; } } public virtual string username { { return this._profilebase.username; } } public virtual bool isanonymous { { return this._profilebase.isanonymous; } } public virtual bool isdirty { { return this._profilebase.isdirty; } } public virtual system.datetime lastactivitydate { { return this._profilebase.lastactivitydate; } } public virtual system.datetime lastupdateddate { { return this._profilebase.lastupdateddate; } } public virtual system.configuration.settingsprovidercollection providers { { return this._profilebase.providers; } } public virtual system.configuration.settingspropertyvaluecollection propertyvalues { { return this._profilebase.propertyvalues; } } public virtual system.configuration.settingscontext context { { return this._profilebase.context; } } public virtual bool issynchronized { { return this._profilebase.issynchronized; } } public static system.configuration.settingspropertycollection properties { { return system.web.profile.profilebase.properties; } } public static webprofile getprofile(string username) { return new webprofile(system.web.profile.profilebase.create(username)); } public static webprofile getprofile(string username, bool authenticated) { return new webprofile(system.web.profile.profilebase.create(username, authenticated)); } public virtual object getpropertyvalue(string propertyname) { return this._profilebase.getpropertyvalue(propertyname); } public virtual void setpropertyvalue(string propertyname, object propertyvalue) { this._profilebase.setpropertyvalue(propertyname, propertyvalue); } public virtual system.web.profile.profilegroupbase getprofilegroup(string groupname) { return this._profilebase.getprofilegroup(groupname); } public virtual void initialize(string username, bool isauthenticated) { this._profilebase.initialize(username, isauthenticated); } public virtual void save() { this._profilebase.save(); } public virtual void initialize(system.configuration.settingscontext context, system.configuration.settingspropertycollection properties, system.configuration.settingsprovidercollection providers) { this._profilebase.initialize(context, properties, providers); } public static system.configuration.settingsbase synchronized(system.configuration.settingsbase settingsbase) { return system.web.profile.profilebase.synchronized(settingsbase); } public static system.web.profile.profilebase create(string username) { return system.web.profile.profilebase.create(username); } public static system.web.profile.profilebase create(string username, bool isauthenticated) { return system.web.profile.profilebase.create(username, isauthenticated); } }
if load profile programmatically modify code below set values believe should trick:
var profile = profilebase.create(username); profile.setpropertyvalue("myguid", aguid); profile.setpropertyvalue("mystring", astring); // etc profile.save()
Comments
Post a Comment