Need Help Calling New Instance of MembershipUser Within Custom UserClass

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top