ASP.NET Custom MembershipProvider, change the semantics of CreateUser, or add a new method

Is there a way to add an additional let say method with such semantics:

CreateUser(User user, UserInfo userInfo, IsInRole isInRole, <any another things here>) 

I can create my own method and call this method separately, but in order to constantly save the poses, I just wonder if there is a way to configure MembershipProviderhow to do this or do something like that?

+3
source share
1 answer

I assume that you have already created a custom membership provider. You can simply add this method and then use it in your application. Say you have a custom membership provider, such as pseudo (simplified) code:

public class CustomMP : MembershipProvider
{
    var db = // your data (member) storage

    public void CreateUser(string username, UserInfo userInfo, /* etc... */)
    {
        // process data
        // create new user instance.. like:
        MyUser newUser = new MyUser(/* params */);

        db.AppUsers.Add(newUser);
        db.SaveChanges();
    } 
}

( .)

public ActionResult CreateMyUser(SomeModel model)
{
    if (ModelState.IsValid)
    {
        // create instance of your custom mebership provider
        // (unless you already have one somewhere else ... as you should)
        CustomMP cmp = new CustomMP();

        // call your new method
        cmp.CreateUser(model.username, model.userInfo, /* etc.. */);

        // login newly created user (optional)
        FormsAuthentication.SetAuthCookie(model.username, false /* = don't create persistent cookie);
        return RedirectToAction("Index","Home");
    }
}

- , , . , , .

+3

All Articles