Membership/roles help

J

John

Hi

I have looked in help but am not clear how to do the following in vb.net
code.

1. Check if a user belongs to a specific role.

2. Change user's password. Is it possible to do it without knowing the
old/existing password?

Would appreciate if someone could give me some pointers.

Thanks

Regards
 
K

Ken Cox [Microsoft MVP]

Hi John,
1. Check if a user belongs to a specific role.

Label1.Text = "Is JackieReeve an Elite Member?:" &
Roles.IsUserInRole("JackieReeve", "EliteMember").ToString

http://msdn2.microsoft.com/en-us/library/system.web.security.roles.isuserinrole.aspx
2. Change user's password. Is it possible to do it without knowing the
old/existing password?

Label2.Text = mbrCurrentMember.ResetPassword("Beatles")

http://msdn2.microsoft.com/en-us/library/d94bdzz2.aspx

Full code below.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mbrCurrentMember As System.Web.Security.MembershipUser
mbrCurrentMember = Membership.GetUser("JackieReeve", True)
Label1.Text = "Is JackieReeve an Elite Member?:" & _
Roles.IsUserInRole("JackieReeve", "EliteMember").ToString
If Membership.EnablePasswordReset = True Then
Label2.Text = mbrCurrentMember.ResetPassword("Beatles")
Else
Label2.Text = "Password reset not allowed."
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Membership password reset</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label id="Label1" runat="server" font-bold="True"
font-size="X-Large" text="Updating Members"></asp:label><br />
<br />
<asp:label id="Label2" runat="server"
font-size="X-Large"></asp:label><br />
<br />
</div>
</form>
</body>
</html>
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top