CreateUserWizard - membership and roles

Discussion in 'ASP .Net Web Controls' started by Sherman KB, Jun 7, 2006.

  1. Sherman KB

    Sherman KB Guest

    I have the need to be able to create users and add them to a role. I'll also
    need to associate the data with some other data. I'm using the sql provider,
    and I'm looking for a way to wrap this data in a transaction. It looks like
    the membership.create users either works for fails, and the roles.addusers
    works the same. Ideally I'd like to hook both the membership.add and
    roles.addusers into one atomic transaction. Is this possible?
    --
    Ken S
     
    Sherman KB, Jun 7, 2006
    #1
    1. Advertising

  2. Sherman KB

    PeterKellner Guest

    On Wed, 7 Jun 2006 09:15:02 -0700, Sherman KB
    <> wrote:

    >I have the need to be able to create users and add them to a role. I'll also
    >need to associate the data with some other data. I'm using the sql provider,
    >and I'm looking for a way to wrap this data in a transaction. It looks like
    >the membership.create users either works for fails, and the roles.addusers
    >works the same. Ideally I'd like to hook both the membership.add and
    >roles.addusers into one atomic transaction. Is this possible?


    In this case, Transaction Scope's are your friend. You can read about
    it here:

    http://msdn2.microsoft.com/en-us/ms172152.aspx

    Your code should look something like what I have below. (I even
    tested it) With the throw in, the user doesn't get added even though
    the CreateUser call is made successfully. (as I had hoped).

    protected void Button1_Click(object sender, EventArgs e)
    {
    using (TransactionScope scope = new TransactionScope())
    {
    MembershipCreateStatus mstatus;
    Membership.CreateUser("newuseryyy", "pass@word",
    "", "q", "a", true, out mstatus);

    throw new ApplicationException("aborting, user should not
    be added");

    scope.Complete();

    }

    Good Luck
    Peter Kellner
    http://peterkellner.net
     
    PeterKellner, Jun 10, 2006
    #2
    1. Advertising

  3. Sherman KB

    Sherman KB Guest

    Peter,

    Thanks for the tip. That should work.
    --
    Ken S


    "PeterKellner" wrote:

    > On Wed, 7 Jun 2006 09:15:02 -0700, Sherman KB
    > <> wrote:
    >
    > >I have the need to be able to create users and add them to a role. I'll also
    > >need to associate the data with some other data. I'm using the sql provider,
    > >and I'm looking for a way to wrap this data in a transaction. It looks like
    > >the membership.create users either works for fails, and the roles.addusers
    > >works the same. Ideally I'd like to hook both the membership.add and
    > >roles.addusers into one atomic transaction. Is this possible?

    >
    > In this case, Transaction Scope's are your friend. You can read about
    > it here:
    >
    > http://msdn2.microsoft.com/en-us/ms172152.aspx
    >
    > Your code should look something like what I have below. (I even
    > tested it) With the throw in, the user doesn't get added even though
    > the CreateUser call is made successfully. (as I had hoped).
    >
    > protected void Button1_Click(object sender, EventArgs e)
    > {
    > using (TransactionScope scope = new TransactionScope())
    > {
    > MembershipCreateStatus mstatus;
    > Membership.CreateUser("newuseryyy", "pass@word",
    > "", "q", "a", true, out mstatus);
    >
    > throw new ApplicationException("aborting, user should not
    > be added");
    >
    > scope.Complete();
    >
    > }
    >
    > Good Luck
    > Peter Kellner
    > http://peterkellner.net
    >
     
    Sherman KB, Jun 12, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    377
  2. guoqi zheng
    Replies:
    2
    Views:
    3,485
    Guoqi Zheng
    Jun 2, 2006
  3. =?Utf-8?B?R3V5IFN3YXJ0d29vZA==?=

    CreateUserWizard and Forms Authentication w/Roles

    =?Utf-8?B?R3V5IFN3YXJ0d29vZA==?=, Jul 14, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    4,117
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 14, 2006
  4. Jéjé
    Replies:
    0
    Views:
    242
    Jéjé
    Sep 27, 2005
  5. Replies:
    1
    Views:
    114
    Joe Kaplan
    Mar 9, 2007
Loading...

Share This Page