Need Help Calling New Instance of MembershipUser Within Custom UserClass

Discussion in 'ASP .Net' started by pbd22, Feb 13, 2010.

  1. pbd22

    pbd22 Guest

    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;
    }
     
    pbd22, Feb 13, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff
    Replies:
    3
    Views:
    1,150
    9-11 Was An Inside Job
    Mar 29, 2007
  2. Neal

    Custom MembershipUser and WSAT

    Neal, Jun 13, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    2,007
    p_romm
    Aug 17, 2008
  3. CSharpner
    Replies:
    1
    Views:
    917
  4. dave
    Replies:
    0
    Views:
    112
  5. Greg Hauptmann
    Replies:
    9
    Views:
    271
    Loren Segal
    Jun 16, 2008
Loading...

Share This Page