Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > CreateUserWizard - membership and roles

Reply
Thread Tools

CreateUserWizard - membership and roles

 
 
Sherman KB
Guest
Posts: n/a
 
      06-07-2006
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
 
Reply With Quote
 
 
 
 
PeterKellner
Guest
Posts: n/a
 
      06-10-2006
On Wed, 7 Jun 2006 09:15:02 -0700, Sherman KB
<(E-Mail Removed)> 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",
"(E-Mail Removed)", "q", "a", true, out mstatus);

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

scope.Complete();

}

Good Luck
Peter Kellner
http://peterkellner.net
 
Reply With Quote
 
 
 
 
Sherman KB
Guest
Posts: n/a
 
      06-12-2006
Peter,

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


"PeterKellner" wrote:

> On Wed, 7 Jun 2006 09:15:02 -0700, Sherman KB
> <(E-Mail Removed)> 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",
> "(E-Mail Removed)", "q", "a", true, out mstatus);
>
> throw new ApplicationException("aborting, user should not
> be added");
>
> scope.Complete();
>
> }
>
> Good Luck
> Peter Kellner
> http://peterkellner.net
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using AD and a Table for Membership and Roles jim.stanley@alumni.usc.edu ASP .Net Security 1 03-09-2007 09:08 PM
CreateUserWizard and Forms Authentication w/Roles =?Utf-8?B?R3V5IFN3YXJ0d29vZA==?= ASP .Net 4 07-14-2006 08:49 PM
membership createuserwizard add extended property. guoqi zheng ASP .Net 2 06-02-2006 05:52 AM
Membership and Roles Question Active Directory or Database? needin4mation@gmail.com ASP .Net 0 03-22-2006 04:22 PM
Application level roles + Item level roles... how to do it? Jéjé ASP .Net Security 0 09-26-2005 11:06 PM



Advertisments