Saving additional data in aspnet_profile table with membership data

I use the membership API with the OpenId implementation in my MVC2-based project. In addition to the username, I need other fields that will be associated with the user during registration.

I'm not sure though, but I think the asp.net profile system is built for this type of requirement. In addition, I see a table with other membership tables called "aspnet_profile".

I added the following parameters to the web.config application to enable the profile:

<profile enabled="true">
      <properties>
        <add  name="FullName" allowAnonymous="false"/>

      </properties>

    </profile>

As already mentioned, the application requires several additional data that must be associated with the user, so when creating a user using the membership API, I added a few more lines of code to enter the profile table

System.Web.Security.MembershipCreateStatus status = MembershipService.CreateUser(userModel.UserName, userModel.Password, userModel.UserName);

                   if (status == System.Web.Security.MembershipCreateStatus.Success)
                   {
                       FormsService.SignIn(userModel.UserName, true);
                       Session["Username"] = userModel.UserName;

                       dynamic profile = ProfileBase.Create(MembershipService.GetUser(userModel.UserName).UserName);
                       profile.FullName = userModel.UserFullName;
                       profile.Save();

                       RedirectToAction("Tech", "Home");



                   }

, aspnet_profile . , , .

+5
3

, , web.config:

<profile enabled="true" defaultProvider="AspNetSqlProfileProvider">
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" applicationName="/" connectionStringName="ApplicationServices" type="System.Web.Profile.SqlProfileProvider" />
      </providers>

      <properties>
        <add  name="FullName" allowAnonymous="false"/>

      </properties>

    </profile>

ProfileBase.Create Profile.FullName;

profile.Initialize(userModel.userName, true);

- aspnet_profile :)

+4

ASP.NET - . - ASp.NET runtime it-self. HttpContext.Current.Profile Profile . , ,

Profile.UserName = "User Name"; 

There is no need to call a method Save. See this article for more information .

In a web application, you cannot really refer to the dynamically created Profile class, so you need to work with HttpContext.Current.Profile(you can, of course, assign it to a variable dynamicfor more readable code, as you did). Another way is to write your own class .

+1
source

All Articles