.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Roles.GetAllRoles() And Membership.GetAllUsers() Not Working.

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :ASP.Net

Hello Forum,


I have been attempting to load my users and roles into a couple of listboxes but for some reason the listboxes are showing up empty.  What am I doing wrong?


<%@ Page Language="VB" MasterPageFile="~/PEPMasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Untitled Page" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script runat="server">

Dim rolesArray() As String
Dim users As MembershipUserCollection

    Public Sub Page_Load()

        Msg.Text = ""

        If Not IsPostBack Then
            ' Bind roles to ListBox.

            rolesArray = Roles.GetAllRoles()
            RolesListBox.DataSource = rolesArray

            ' Bind users to ListBox.

            users = Membership.GetAllUsers()
            UsersListBox.DataSource = users
        End If
    End Sub

Public Sub AddUser_OnClick(sender As Object, args As EventArgs)


View Complete Post

More Related Resource Links

FileUpload Control with membership and roles


Hi Everyone!

I'm pretty new to development using Microsoft technologies.

I'm trying to build a portal kind of an application in asp.net, in which one of the functionality is letting people log in and upload their documents. The upload page is only accessible to registered users of the portal.


I would like to track the user uploaded files according to their userIds.

Is it possible to use the FileUpload Control and C# to fetch the current user id, create a directory with the same name(as that of userID) in the file system and upload the files( multiple file upload, if necessary) into it?

Also another admin page would have to be able to see the list of files uploaded by the specific user and download it if necessary.

Could anyone help me with this?

I'm also expecting alternate solutions to the problem.

Awaiting a response.

Thanks in advance 


Multiple groups of roles in membership

Hi,I am developing this website which requires multiple groups of roles inside membership.Here is an example:I want to create a group of states (would be the first group of roles):* Oregon* California* Kansas* Texas* OhioAnd then a second group of profiles:* Admin* Section 1* Section 2* Section 3Then I want to comine these groups, so for example:* Patrick has Oregon and Section 1 role, so he can only access the state of Oregon and Section 1 module on the website.* Laura has Kansas and Section 2 role, so she can only access the state of Kansas and Section 2 module on the website.* John has Ohio, Texas and Admin and Section 1 roles, so he can only....Do you understand what I mean? How can I achieve this with .net memberhip?

Check membership roles

Hello All, I have the following, for an webapplication I user membership roles. Users are added or removed from a role. I have two things i am wondering how to accomplish.   The first: New or exisiting users have assigned roles for their accounts. This roles can be selected or deselected from a checkbox (when the users is created or edited) . I want to build some routine or function to see if a users is part of a role or if he is assigned a new role. When, in edit mode, a users is part of a role the particular checkbox has to be checked, or if he isn't unchecked. Of course I want to call a function to do that so I don;t have to write the if then statement for all roles, but just one time. I think this should be a public function to call from all pages within the appication, but whatever i try, it doesnt work.  I have written a function in a apart classfile called functions.vb. But the roles syntax isn't recognized. Herby the function{Public Function CheckMembership(ByVal GroupName As Boolean, ByVal User As String, ByVal Group As String) As Integer If GroupName = True Then If Not Roles.IsUserInRole(User, Group) Then Roles.AddUserToRole(User, Group) ElseIf GroupName = False Then If Roles.IsUserInRole(User, Group) Then Roles.RemoveUserFromRole(User, Group)

how to customize asp.net membership roles to create separate member area ?


I am using asp.net membership for all the users and roles, right now i have a website on which i have created 2 roles "admin" and "member"

in this website i create accounts, so all the accounts are separated/distinguished by account name

now i was to add one more role "accountholders" and i want to add this role in such a way that an account holder will be able to see his / her account's stuff ...

i as admin will be creating username and password for accountholders and i will provide them their login credentials so that they can login and see what's in their account.

My idea of creating account is that, the accounts that i have in my database will be the key, so when i will create username for particular account , in the create user wizard i should have a drop downmenu will all the accounts name. so the user that i am creating will be linked on that account only ..

how to accoplish this ? please guide me in a right direction...

Membership login not working



I am developing a website in which giving login functionality through membership and asp.net login control.My membership login was working fine but now its not working.

I m checking authentication through HttpContext.Current.User.Identity.IsAuthenticated but it always return false.

And when checking through Membership.ValidateUser(Login1.UserName, Login1.Password) it gets authenticated..

why this is happening.........

plz help........

profiles, membership and roles


Dear All,

Can someone help me with creating a custom profile, membership and role page something like this:


I'm trying to edit this as my requirment but I can't make it work. I will just need to add detailview to view the entire profile since it's to long for the gridview to handle.

I need to display the gridview custom data then by selecting the select, it will be displayed on the detailview to edit and delete. In create user, need to add my data requirement by making a createwizard page on the left table same as the link. 

AspNet Membership Login Stoped Working !!!


Hello all

I have a web app that uses the Membership Provider to authenticate users.

Everything worked fine until today... when I tryed to log in it failed.

I looked in the database if something went wrong there and the user is deleted but everything looks fine there.

I tryed to recover the password using the user name and i got an error that the user is not recognized.

I tyed to recover the password (even though I am sure what the password is) but still no luck... (I get an error that hased passwords can not be decrypted)

I triyed it in local host and guess what ... still the same...

this is the provider section in my web config

    <membership defaultProvider="SqlMemberShipProvider">
        <remove name="SqlMemberShipProvider"/>
        <add name="SqlMemberShipProvider" 

Any i

.Net 3.5 Membership DB not working with .net 4.0?


Hey All

I am working on a new application that will feed off my application's DB that was written with .net 3.5 (really 2.0, since thats where the aspnet_regsql.exe lives)... I open up the application settings page on my old VS2008 application, and see all my 4000+ users, but if i link the membership to that database in VS2010 with asp .net 4.0, it shows 0. I have verified the connections, and i also noticed there is a net aspnet_regsql.exe in the 4.0 framework folder.

Is there any way to make the old membership work, or a way to migrate my users? If not, i would think this would cause a LOT of issues with many .net applications with many forms based users.  

IIdentity, IPrincipal, membership and roles provider



How I must use this? I create custom principal for implement logic for users. In identity I store Id, Name. But it abnormally - this classes must use for authenticate and authorize. 

I can implement custom MembershipUser, custom Roles and Membership provider. 

IIdentity, IPrincipal, membership and roles provider



How I must use this? I create custom principal for implement logic for users. In identity I store Id, Name. But it abnormally - this classes must use for authenticate and authorize. 

I can implement custom MembershipUser, custom Roles and Membership provider. 

How to do it? What best practices are?

Best regards,

Peshkov Evgeniy.

Do Membership Roles work with custom connection string?


Hi all, plz help with one issue.
I have Membership configured with IIS7, tables for it located in my own database, created with aspnet_regsql utility, and I am using custom connection string to access it.

This is part of web.config related to Membership :

        <add connectionString="Server=CORESERVER\SQLExpress;Database=Shop;User ID=Tema;Password=Matrix" name="CustomSqlConnection" />
    <profile enabled="true">
            <add name="CustomSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="CustomSqlConnection" />
    <roleManager defaultProvider="AspNetSqlRoleProvider" enabled="true">
            <add name="CustomSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="CustomSqlConnection" />
    <membership defaultProvider="CustomSqlMemberPr

How to use ASP.NET's Membership, Roles etc. in asp.net 4.0?


Good morning everybody.

I want to practise ASP.NET Authentication, and Authorization features in Visual Studio 2010.

I wanted to store user account information NOT IN THE aspnet db, but in a SEPARATE database. Hence, I have tried to use aspnet_regiis tool at visual studio command prompt. I am not presenting with wizard type window. Without wizard, I don't know how to store user information in a separate database otherthan aspnet db.

Can anybody please suggest any solution for this.

Also, one more thing:

It looks like lot of features have been changed in Visual Studio 2010 to work with Forms Authentication. If it is really changed, can anybody please suggest me the better resources to learn on the web?

Thansk in advance,
Ashok kumar.

Roles.GetRolesForUser(UserName) not working


Roles.GetRolesForUser(UserName) .

I have follwing codes in my Web.config,

<authentication mode="Forms">
      <forms slidingExpiration="true" defaultUrl="admin/Welcome.aspx" timeout="60"/>    </authentication>

<roleManager enabled="true" defaultProvider="SecurityTutorialsSqlRoleProvider">
        <add name="SecurityTutorialsSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" applicationName="SecurityTutorials" connectionStringName="SecurityTutorialsConnectionString"/>


Any help is appreciated.

'GetAllUsers' is not a member of 'Membership'.



I have a problem with Membership in ASP.NET. I'm using membership on my website. So far, I can create user and login using the created user account.

Then, I want to create an Administration Page which will display all users created in my membership DB (ASPNETDB).

I designed the layout and I want to display all the created users on a ListBox.

In the code behind, in Page_Load event procedure, I use this code:

If Not IsPostBack Then
            Dim allUsers As MembershipUserCollection = Membership.GetAllUsers()
            Dim currentUser As MembershipUser
            For Each currentUser In allUsers
                If Roles.IsUserInRole(currentUser.UserName, "Admins") Then
                End If
End If

When I compiled and tried this Admin Page, the Page gave me this error :

Server Error in '/MySite' Application.

Compilation Error

Description: An error occurred during the compilatio

Membership and roles in ASP.net 3.5



I would like to know about roles in asp.net.Actually I am using VS2008 and SQL Server 2008.

Here I have to implement admin,L1,L2,Employee roles and their access assign by admin.

Here all machines are in network.I have also limited access.

I want to implement roles only for stand alone PC. Please advice the better way.


Help in Membership schema and roles


hi all,

i am making a website when i m almost 25% my manager told me to add roles and stuff...my problem is how to make roles in nested manner.

my website has Admin and users(admin, area manager, site manager, user) and then on the default page i need to disable enable buttons according to companies e.g starbucks should not access accident modules etc etc

so i am really confused how to make roles in nested manner. any assistance is welcome

thanks in advance

WCF and ASP.Net Membership, Roles and Profile



I have a client asp.net website that uses  ASP.Net Membership, Roles and Profile providers and Login controls.

I need to expand the application so was going to use WCF Workflows, the ASP.Net website will be hosted on a different server than the WCF Services so what I want to do is get the ASP.Net Website to auth via the WCF Service.

So process will go:

ASP.Net Website ------------------> WCF Service ------------------> SQL Database (Membership, Roles, Profile, Workflow Persistence Data and Business Data)

I tried creating a custom Membership and Role providers but I have had problems managing the users (Membershipuser class) saying null when a vaild user has been return by the WCF Service as can access the properies but not the methods.

Am I doing this the right way or is there other built in classes that I have missed?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend