如何使用ASP.Net成员资格提供程序添加配置文件字段?

时间:2011-12-13 09:16:07

标签: asp.net-mvc asp.net-membership asp.net-profiles

我正在使用ASP.NET成员资格提供程序处理应用程序。默认情况下,我可以使用一些字段,如用户名,密码。如何添加到asp.net成员资格提供程序,以便我可以在寄存器部分添加“firstName”,“lastName”等配置文件字段,并将其与其他数据一起保存到aspnet_profile表中的数据库中。

我正在帐户模型中创建一个用户,如下所示:

    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
            // Attempt to register the user
            MembershipCreateStatus createStatus;
            Membership.CreateUser(model.UserName, model.Password,
            model.Email,model.PasswordQuestion,model.PasswordAnswer,
            true, null,out createStatus);
            if (createStatus == MembershipCreateStatus.Success)
            {
                FormsAuthentication.SetAuthCookie(model.UserName, false);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", ErrorCodeToString(createStatus));
            }
        }

        return View(model);
    }

现在我应该使用哪个函数将配置文件信息存储到db中? 帮帮我!!

1 个答案:

答案 0 :(得分:3)

将字段添加到Web.Config的配置文件部分。

<profile>
 <properties>
  <add name="FirstName" />
  <add name="LastName" />
  <add name="Address1" />
  <add name="Address2" />
  <add name="City" />
  <add name="State" />
  <add name="Zip" />
  <add name="Phone" />
  <add name="ProfileVersion" type="int" defaultValue="0" />
  </properties>
 </profile>

有关详细信息,请访问:http://msdn.microsoft.com/en-us/magazine/cc163457.aspx

相关问题