开发者

MVC3 Membership Profile Conversion from ASP.NET

I am converting a web application from asp.net to MVC3 and am trying to figure out how to set and access the profile properties that were configured in the old application.

I can access the database from the old app and I can create new users using MVC3 using

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

This new user is placed in the database "USER" table. I need to also store additional information about the user and I must still user the old database that was created in the old application so when we switch over to the new app the cu开发者_JAVA技巧rrent users can still logon and not notice a change other than some layout improvements.

The old database also has a table in it called "PROFILE" which stored the additional values like so

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

This was created using the MembershipWizard which is not available in MVC3. I need to find a way to create users with MVC3 and still add the appropriate values to this table.

Thank you in advance for any help you can provide.


You can make your own Membership class... Try implementing the MembershipProvider class and register it in your Web.Config...

It's very flexible way to handle Membership. I use it all the time...


The default MVC 3 internet application template includes a method in the interface for create user as:

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);
}

with its implementation as:

        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;
    }

So - you need to

  1. Add (or change the existing method) the new params to your method signature

  2. Add the params to the interface method (or create a new method on the interface)

  3. Change the function call to _provider.CreateUser to pass in your parameters

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜