How to get of last created user using CreateUserWizard?

R

Rodusa

Could someone please recommend the best way and how to obtain the last
inserted userid of users (security) table using the Button click event
of CreateUserWizard? In classic Asp and Asp.net 1.x I used the
@@identity to get the last inserted record of my custom table, but now
I don't know how Asp.net does that. I would like to understand how it
works behind the scenes, the sequence of processing. I saw that there
is an event called createuser in CreateUserWizard control which is
fired after the user is created. Is this the best place to implement
the get the last userid? In addition, is it safe? Does it garantee
that no other user will get that userid and that locks that value to
used in this same event?

Thanks
Rod
 
B

Brock Allen

The CreateUserWizard fires a UserCreated event. Once that's fired, you can
access the Username and Password properties of the control. With the Username
if you need to you should be able to call into the Membership class to get
anything else you need.
 
R

Rodusa

Brock, I am new to security in Asp.net 2.0. Can you provide some
example of how to get the last created userid using the
membershipclass?

Thank you

Rod
 
B

Brock Allen

<asp:CreateUserWizard runat=server ID=_createUser OnCreatedUser="_createUser_CreatedUser"></asp:CreateUserWizard>

<script runat="server">
protected void _createUser_CreatedUser(object sender, EventArgs e)
{
string name = _createUser.UserName;
MembershipUser user = Membership.GetUser(name);
object key = user.ProviderUserKey;
}
</script>
 
R

Rodusa

I see that you assume that the the login name should be unique. Anyhow,
this is perfect and works great.

Thanks for your fast response.

Rod
 
B

Brock Allen

The login name is unique within the scope of the application. That's the
Membership model.
 
M

Mateusz Kierepka

I have one additional question:
How can I use only email instead using UserID? I try to set
RequireEmail="False" and use only UserName, but validation always says
your's email is in wrong format...

Regards
Mateusz www.Kierepka.pl ;)
 
D

Dominick Baier [DevelopMentor]

Hi,

you can set email requirements on the control and the provider - have you
set both??
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top