0

我正在将 Web 应用程序从 asp.net 转换为 MVC3,并试图弄清楚如何设置和访问在旧应用程序中配置的配置文件属性。

我可以从旧应用程序访问数据库,我可以使用 MVC3 创建新用户

Membership.CreateUser(model.UserName, model.Password, model.Email, model.SecretQuestion, model.SecretAnswer, true, out createStatus);

这个新用户被放置在数据库“USER”表中。我还需要存储有关用户的其他信息,并且我必须仍然使用在旧应用程序中创建的旧数据库,因此当我们切换到新应用程序时,当前用户仍然可以登录并且除了一些布局改进之外不会注意到任何变化.

旧数据库中还有一个名为“PROFILE”的表,它存储了像这样的附加值

UserId , PropertyNames , PropertyValuesString , PropertyValuesBinary , LastUpdatedDate

DB7E1F8E-FB45-49E5-A2AF-C83A371CC22F,PartnerID:S:0:2:FirstName:S:2:4:LastName:S:6:12:Indexed:S:18:1:, 26MiloMinderbinder3, 0x, 2010-09 -29 21:23:33.737

这是使用 MVC3 中不可用的 MembershipWizard 创建的。我需要找到一种使用 MVC3 创建用户的方法,并且仍然将适当的值添加到该表中。

提前感谢您提供的任何帮助。

4

2 回答 2

0

您可以创建自己的 Membership 类...尝试实现 MembershipProvider 类并在您的 Web.Config 中注册它...

这是处理会员资格的非常灵活的方式。我用它所有的时间...

于 2011-08-09T17:39:22.350 回答
0

默认的 MVC 3 Internet 应用程序模板在界面中包含一个用于创建用户的方法:

public interface IMembershipService
{
    int MinPasswordLength { get; }

    bool ValidateUser(string userName, string password);
    MembershipCreateStatus CreateUser(string userName, string password, string email);
    bool ChangePassword(string userName, string oldPassword, string newPassword);
}

其实现为:

        public MembershipCreateStatus CreateUser(string userName, string password, string email)
    {
        if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
        if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");
        if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "email");

        MembershipCreateStatus status;
        _provider.CreateUser(userName, password, email, null, null, true, null, out status);
        return status;
    }

所以 - 你需要

  1. 将新参数添加(或更改现有方法)到您的方法签名

  2. 将参数添加到接口方法(或在接口上创建新方法)

  3. 将函数调用更改为 _provider.CreateUser 以传入您的参数

于 2011-08-09T19:08:59.203 回答