Using the ASP.NET SQL Memberhip Provider, how can I store my own data for each user?

I am using an ASP.NET SQL membership provider. So, there is a table aspnet_Usersin which there is data about each of my users. (In fact, the table aspnet_Membershipappears to contain most of the evidence).

Now I want to save some information for each user in my database, so I thought that I was just creating a new table with a column UserId(GUID) and the ratio of FK to aspnet_Users. However, I found that I cannot easily access UserId, because it is not displayed through the membership API. (I know I can access it through ProviderUserKey, but it looks like the API is abstracting the internal UserIdin favor UserName, and I don't want to go too far against the grain).

So, I thought that instead I should put a column LoweredUserNamein my table and create an FK relation with it aspnet_Users. Bzzzt. Wrong, because although aspnet_Usersthere is a unique index in it LoweredUserName, it also includes ApplicationId- therefore, to create an FK relationship, I need to have a column ApplicationIdin my table too.

At first I thought: okay, I only deal with one application, so I just add such a column and give it a default value. Then I realized what ApplicationIda GUID is, so it would be painful to do this. It’s not difficult, but until I show my database, I can’t predict what the GUID will be.

It seems to me that I'm missing something, or something is wrong. What should I do?

+5
4

, ProfileProvider, .

ASP.NET

. ProfileProvider , , ProfileProvider, , System.Web.Profile.ProfileProvider. -, , .

SqlMembershipProvider. , Membership , UserId. , , SqlMembershipProvider. , , .

UserId, , , aspnet_Users , . LowerUsername ( ApplicationId) , , .

+9

. . :

(web.config):

<profile enabled="true" defaultProvider="MyProvider">
    <providers>
        <add name="MyProvider" connectionStringName="MembershipCnnStr" applicationName="MyApp" type="System.Web.Profile.SqlProfileProvider"/>
    </providers>
    <properties>
        <add name="EmployeeId" type="String" />
        <group name="UserSettings">
            <add name="IsSandboxMode" type="Boolean" defaultValue="false" />
            <add name="Shortcuts" type="System.Collections.Generic.List`1[System.string]" />
        </group>
    </properties>
</profile>
+5

, , , Personalization.

, - , , .

, , .

+3

.cs,

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        FirstNameTextBox.Text = Server.HtmlDecode(Profile.FirstName);
        LastNameTextBox.Text = Server.HtmlDecode(Profile.LastName);

    }

}

web.config

 <profile>
  <providers>
      <add name="FirstName" type="System.String"/>
      <add name="LastName" type="System.String"/>
      <add name="MemberId" defaultValue="0" type="System.Int32"/>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
  </providers>
</profile>
+1

All Articles