Previous Thread:   Customizing the Calendar Control

6/7/2006 9:15:02 AM    CreateUserWizard - membership and roles
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



6/9/2006 7:11:29 PM    Re: CreateUserWizard - membership and roles
On Wed, 7 Jun 2006 09:15:02 -0700, Sherman KB  
  
<ShermanKB@discussions.microsoft.com> wrote:  
  
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",  
  
"peter@Peterkellner.net", "q", "a", true, out mstatus);  
  
throw new ApplicationException("aborting, user should not  
  
be added");  
  
scope.Complete();  
  
}  
  
Good Luck  
  
Peter Kellner  
  
http://peterkellner.net