P
pbd22
Hi.
I am getting myself mixed up trying to tie together ASPNET 2.0's
MembershipUser and ProfileBase in addition to come custom fields in
the same User class.
I am close, but am having a hard time accessing the MembershipUser
methods - I geek getting "object reference not set to an instance of
an object" or errors of that ilk.
Could somebody please show me how to tie in MembershipUser into my
User class? I am also open to putting both ProfileBase and
MembershipUser into an interface but would appreciate if somebody
could provide a code example of how to do this if you thing that is
the best way.
Below is the core structure of my User class.
Thanks in advance for your help.
public class User : ProfileBase, ISessionMgrEntry
private readonly MembershipUser _MembershipUser;
public User()
{
// I THINK THE WAY I AM DOING THINGS HERE IS
// WHY I AM HAVING PROBLEMS. I HAVE ALSO TRIED
// NEW MembershipUser(); BUT THAT THROWS THE
// INSTANCE ERROR.
_MembershipUser = Membership.GetUser();
}
// I AM USING THIS METHOD TO ACCESS THE USER OBJECT
public static User GetUserProfile(string username)
{
return System.Web.Profile.ProfileBase.Create(username) as User;
}
// THIS IS AN EXAMPLE OF A PROPERTY THAT ACCESSES MEMBERSHIPUSER
public string Comment
{
get { return _MembershipUser.Comment; }
set { _MembershipUser.Comment = value; }
}
// THIS IS AN EXAMPLE OF A CUSTOM DATA PROPERTY (IT EXTENDS THE
ASPNET_DB)
[SettingsAllowAnonymous(false),
CustomProviderData("FirstName;string")]
public string FirstName { get { return base["FirstName"]
as string; } set { base["FirstName"] = value; } }
// THIS IS AN EXAMPLE OF A PROPERTY IN THE ISESSIONMGRENTRY INTERFACE
public long? SessionId
{
get;
set;
}
I am getting myself mixed up trying to tie together ASPNET 2.0's
MembershipUser and ProfileBase in addition to come custom fields in
the same User class.
I am close, but am having a hard time accessing the MembershipUser
methods - I geek getting "object reference not set to an instance of
an object" or errors of that ilk.
Could somebody please show me how to tie in MembershipUser into my
User class? I am also open to putting both ProfileBase and
MembershipUser into an interface but would appreciate if somebody
could provide a code example of how to do this if you thing that is
the best way.
Below is the core structure of my User class.
Thanks in advance for your help.
public class User : ProfileBase, ISessionMgrEntry
private readonly MembershipUser _MembershipUser;
public User()
{
// I THINK THE WAY I AM DOING THINGS HERE IS
// WHY I AM HAVING PROBLEMS. I HAVE ALSO TRIED
// NEW MembershipUser(); BUT THAT THROWS THE
// INSTANCE ERROR.
_MembershipUser = Membership.GetUser();
}
// I AM USING THIS METHOD TO ACCESS THE USER OBJECT
public static User GetUserProfile(string username)
{
return System.Web.Profile.ProfileBase.Create(username) as User;
}
// THIS IS AN EXAMPLE OF A PROPERTY THAT ACCESSES MEMBERSHIPUSER
public string Comment
{
get { return _MembershipUser.Comment; }
set { _MembershipUser.Comment = value; }
}
// THIS IS AN EXAMPLE OF A CUSTOM DATA PROPERTY (IT EXTENDS THE
ASPNET_DB)
[SettingsAllowAnonymous(false),
CustomProviderData("FirstName;string")]
public string FirstName { get { return base["FirstName"]
as string; } set { base["FirstName"] = value; } }
// THIS IS AN EXAMPLE OF A PROPERTY IN THE ISESSIONMGRENTRY INTERFACE
public long? SessionId
{
get;
set;
}