【问题标题】:How to add an profile field using ASP.Net membership provider?如何使用 ASP.Net 会员提供程序添加配置文件字段?
【发布时间】:2012-01-19 04:19:01
【问题描述】:

我正在开发一个使用 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);
    }

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

【问题讨论】:

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


    【解决方案1】:

    将字段添加到 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多