Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 618819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:35:18+00:00 2026-05-13T18:35:18+00:00

I have recently installed the aspnetdb and have been customizing it for the purposes

  • 0

I have recently installed the aspnetdb and have been customizing
it for the purposes of my application design. I have extended the ASPNET
providers as part of my class design: MyMembershipProvider, MyProfileProvider,
and MyRoleProvider. Everything works well there.

Now, per the requierments of my system, I need to add custom data and I don’t
want to use the name / value design provided in aspnet_Profile. So, I have
created two custom tables:

dbo.Profile

CREATE TABLE [dbo].[Profiles](
    [profileid] [int] IDENTITY(1,1) NOT NULL,
    [userid] [uniqueidentifier] NOT NULL,
    [username] [varchar](255) COLLATE Latin1_General_CI_AI NOT NULL,
    [applicationname] [varchar](255) COLLATE Latin1_General_CI_AI NOT NULL,
    [confirmcode] [varchar](255) COLLATE Latin1_General_CI_AI NOT NULL,
    [isanonymous] [bit] NULL,
    [lastactivity] [datetime] NULL,
    [lastupdated] [datetime] NULL,
 CONSTRAINT [PK__Profiles__1DB06A4F] PRIMARY KEY CLUSTERED 
(
    [profileid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [PKProfiles] UNIQUE NONCLUSTERED 
(
    [username] ASC,
    [applicationname] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

and

dbo.ProfileData

CREATE TABLE [dbo].[ProfileData](
    [profiledataid] [int] IDENTITY(1,1) NOT NULL,
    [profileid] [int] NOT NULL,
    [lastname] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
    [firstname] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
    [alternateemail] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
    [zipcode] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
    [birthmonth] [tinyint] NULL,
    [birthday] [tinyint] NULL,
    [birthyear] [int] NULL,
    [gender] [varchar](10) COLLATE Latin1_General_CI_AI NULL,
    [city] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
    [state] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
    [country] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
    [ipaddress] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
    [sessionid] [bigint] NULL,
 CONSTRAINT [PK_ProfileData] PRIMARY KEY CLUSTERED 
(
    [profiledataid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

Now, since I have custom data extending the ASPNET infrastructure, I have
written a custom user class that helps extend that data as part of the profile
snapshot. I basically followed John Galloway’s suggestions in this blog

public class CustomUser : ProfileBase
{

        public customuser() {}

         public static CustomUser GetCustomUserProfile(string username)
        {
            return System.Web.Profile.ProfileBase.Create(username) as CustomUser;
        }

        #region ProfileBase Extended Properties

        [SettingsAllowAnonymous(false), CustomProviderData("FirstName;string")]
        public string FirstName { get { return base["FirstName"] as string; } set { base["FirstName"] = value; } }

        [SettingsAllowAnonymous(false), CustomProviderData("LastName;string")]
        public string LastName { get { return base["LastName"] as string; } set { base["LastName"] = value; } }

        [SettingsAllowAnonymous(false), CustomProviderData("AlternateEmail;string")]
        public string AlternateEmail { get { return base["AlternateEmail"] as string; } set { base["AlternateEmail"] = value; } }

       // AND SO ON...

        #endregion

}

OK, so far so good. I have a CustomUser class that I can use for getting and setting
profile data as such:

CustomUser _cu = CustomUser.GetUserProfile(username);

This will return all my custom fields in addition to the properties inherited from
ProfileBase. Great.

But what if I want to add other properties to the User’s profile? Namely, those provided
by ASPNET’s MembershipUser class such as IsOnline, PasswordQuestion, IsLockedOut, etc…
To get base properties from MembershipUser, I could try something like:

public class CustomUser : MembershipUser
    {
        public CustomUser(string providerName, string name, object providerUserKey, string email,
                                string passwordQuestion, string comment, bool isApproved, bool isLockedOut,
                                DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate,
                                DateTime lastPasswordChangedDate, DateTime lastLockoutDate)
            : base(
                providerName, name, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut,
                creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
        {
        }

        protected CustomUser()
        {
        }

        // e.g. no desire to use Profile, can just add data
        // say, from a flat record containing all user data
        public string MyCustomField { get; set; }
    }

But, because I have also been inheriting from ProfileBase and C# does not
allow multiple inheritance (ie., I can’t do CustomUser: ProfileBase, MembershipUser),
I am stuck with a bit of a problem. What is the best way to architect my user class
so User _user = new User(); returns the full breadth of properties relevant to a authenticated user?

Below is my first stab at this “SuperUser” class but I am having a real hard time
figuring out how to create a new instance of the class object such that both CustomUser
and MembershipUser are created.

Am I going about this the right way?

    public class User
    {

        public User() { }

        public static User GetUserProfile(string username)
        {
             // return combined profile based on username
        }

        #region CustomUser Members

        private CustomUser _customUser
        {
            get
            {       
                if (UserName != null)
                {
                    try
                    {
                        return ProfileBase.Create(UserName) as CustomUser;
                    }
                    catch { return null;  }
                }
                else
                {
                    try 
                    {
                        // this will work if the site user is log'd in
                        return ProfileBase.Create(Membership.GetUser().UserName) as CustomUser;
                    }
                    catch { return null;  }
                }

            }
        }

        public string FirstName
        {
            get
            {
                if (_customUser != null)
                {
                    return _customUser.FirstName;
                }
                return string.Empty;
            }

            set
            {
                if (_customUser != null)
                {
                    _customUser.FirstName = value;
                }
            }
        }

        public string LastName
        {
            get
            {
                if (_customUser != null)
                {
                    return _customUser.LastName;
                }
                return string.Empty;
            }

            set
            {
                if (_customUser != null)
                {
                    _customUser.LastName = value;
                }
            }
        }


        #endregion

        #region MembershipUser Members

        //corresponding MembershipUser
        private MembershipUser _membershipUser
        {
            get
            {
                if (UserName != null)
                {
                    return Membership.GetUser(UserName);
                }
                return null;
            }
        }

        //Properties looked up from MembershipUser

        public string UserName
        {
            get
            {
                if (_membershipUser != null)
                {
                    return _membershipUser.UserName;
                }
                return string.Empty;
            }

        }

        public string Email
        {
            get
            {
                if (_membershipUser != null)
                {
                    return _membershipUser.Email;
                }
                return string.Empty;
            }

        }

        public object ProviderUserKey
        {
            get
            {
                if (_membershipUser != null)
                {
                    return _membershipUser.ProviderUserKey;
                }
                return null;
            }
        }


        #endregion

     }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:35:18+00:00Added an answer on May 13, 2026 at 6:35 pm

    Code, It looks like you are planning to do a lot of unnecessary work.
    And there is no compelling reason to aggregate the membership and profile infrastructure in a wrapper class and many reasons not to.

    The first reason is that you can’t use it anywhere. You will have to build your own infrastructure. I have done it and it aint fun.

    What is fun is coding to an established api and taking advantage of the millions of dollars and thousands of man hours put into designing, developing and testing the provider based systems of ASP.NET.

    If you wish to have a custom membership user the first step is to inherit from MembershipUser so that you can easily implement a custom provider that plugs right into the asp.net framework.

    See here for a very quick and easily digested example and here for the standard docs.

    As far as composing profile within your user. Membership, Roles and Profile are separate but related facets of the infrastructure and have been logically separated to maximize flexibility and reuse.

    I am certain that you will find more value in learning to code to the provider based api and focusing on solving interesting problems than re-inventing the wheel.

    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently installed Visual Studio 2010 Pro. There might have been a link to
I've recently installed Ruby on Rails 3.2 and have been trying to learn it.
Installed a captcha on my blog, been good up until now. There have recently
I have an ASP.NET MVC 3 web application. I recently installed T4MVC templates by
I have recently installed .net 3.5 SP1. When I deployed a compiled web site
I recently installed the Eclipse Metrics Plugin and have exported the data for one
I recently installed the phpBB app using the one click function (I have a
I recently installed xampp, followed the installation. MySQL/apache. (I have same website running on
I've recently installed VS2008. The project I'm working on uses vstest and I have
I have a curious problem: My app is distributed through ClickOnce. I recently installed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.