473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to Get Number of Users in Membership Role

Greetings,

I'm using ASP.NET membership and I'd like to query the number of users in a
particular role.

I don't want the overhead of returning a dataset and then getting the number
of items in it. I'd like to create a stored procedure for maximum efficiency
that returns the number of users in a particular role.

It appears that role IDs are encrypted in the membership tables so I'm not
really sure where to start. I was hoping this wouldn't be that complicated
as I'm pretty new to this.

Thanks for any tips.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Nov 28 '07 #1
5 3279
Huh?

Try these. A RoleId is a uniqueidentifier
select top 1 * from dbo.aspnet_Roles IsAnonymous

--------------------------------------------------------------------------------------------------------------------------------
---------------------------------------- ---- ----------------------------------------
---- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---- ------------------ ---- ----------- ---- ----------------------------------------
----

select top 1 * from dbo.aspnet_Users

--------------------------------------------------------------- ----------------------------------------
---- ---------------------------------------- ----

select top 1 * from dbo.aspnet_UsersInRoles

--------------------------------------------------------------- ----------------------------------------
---- ---------------------------------------- ----

declare @RoleId uniqueidentifier

select @RoleId = (select top 1 RoleId from dbo.aspnet_Roles)

print @RoleID

select count(*) as ThisRoleCount from dbo.aspnet_UsersInRoles where RoleId =
@RoleId

declare @RoleName varchar(12)

select @RoleName = (select top 1 RoleName from dbo.aspnet_Roles)

print @RoleName

select count(*) as ThisRoleCount from dbo.aspnet_UsersInRoles link

join dbo.aspnet_Roles roles on link.RoleId = roles.RoleId

where RoleName = @RoleName

select users.UserId , users.UserName from dbo.aspnet_UsersInRoles link

join dbo.aspnet_Roles roles on link.RoleId = roles.RoleId

join dbo.aspnet_Users users on link.UserId = users.UserId

where RoleName = @RoleName



"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:ey**************@TK2MSFTNGP02.phx.gbl...
Greetings,

I'm using ASP.NET membership and I'd like to query the number of users in
a particular role.

I don't want the overhead of returning a dataset and then getting the
number of items in it. I'd like to create a stored procedure for maximum
efficiency that returns the number of users in a particular role.

It appears that role IDs are encrypted in the membership tables so I'm not
really sure where to start. I was hoping this wouldn't be that complicated
as I'm pretty new to this.

Thanks for any tips.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Nov 28 '07 #2
On Nov 27, 9:29 pm, "Jonathan Wood" <jw...@softcircuits.comwrote:
Greetings,

I'm using ASP.NET membership and I'd like to query the number of users in a
particular role.

I don't want the overhead of returning a dataset and then getting the number
of items in it. I'd like to create a stored procedure for maximum efficiency
that returns the number of users in a particular role.

It appears that role IDs are encrypted in the membership tables so I'm not
really sure where to start. I was hoping this wouldn't be that complicated
as I'm pretty new to this.

Thanks for any tips.
Very simple. No need for a stored procedure...

Imports System.Web.Security
dim count as integer = roles.GetUsersInRole("rolename").Length

Nov 28 '07 #3
Larry,
>I don't want the overhead of returning a dataset and then getting the
number
of items in it. I'd like to create a stored procedure for maximum
efficiency
that returns the number of users in a particular role.

It appears that role IDs are encrypted in the membership tables so I'm
not
really sure where to start. I was hoping this wouldn't be that
complicated
as I'm pretty new to this.

Thanks for any tips.

Very simple. No need for a stored procedure...

Imports System.Web.Security
dim count as integer = roles.GetUsersInRole("rolename").Length
Perhaps I'm missing something here.

My understanding is that, not only does this approach load the entire
dataset of users of a particular role into memory, it then makes a second
copy of that data in an in-memory collection, before finally getting the
number of items in that collection. This strikes me as horribly inefficent,
and would not meet my stated objectives.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Nov 28 '07 #4
On Nov 28, 12:43 pm, "Jonathan Wood" <jw...@softcircuits.comwrote:
Larry,


I don't want the overhead of returning a dataset and then getting the
number
of items in it. I'd like to create a stored procedure for maximum
efficiency
that returns the number of users in a particular role.
It appears that role IDs are encrypted in the membership tables so I'm
not
really sure where to start. I was hoping this wouldn't be that
complicated
as I'm pretty new to this.
Thanks for any tips.
Very simple. No need for a stored procedure...
Imports System.Web.Security
dim count as integer = roles.GetUsersInRole("rolename").Length

Perhaps I'm missing something here.

My understanding is that, not only does this approach load the entire
dataset of users of a particular role into memory, it then makes a second
copy of that data in an in-memory collection, before finally getting the
number of items in that collection. This strikes me as horribly inefficent,
and would not meet my stated objectives.
I cannot comment on how it works, sorry, but I doubt they'd go through
the trouble of making all these functions that are so inefficient as
to be useless.

Maybe a Microsoft guy can chime in.

Nov 28 '07 #5
My queries showed you how to get the info, without "full population".

Did they not meet your objective? Did you look at them?

......

I'd still try to use the included methods...How many users/roles do you
have?
I don't think a <100 users/roles is a big deal.....
But my queries show you how to get around the default "full
population".........

"Larry Bud" <la**********@yahoo.comwrote in message
news:6c**********************************@y20g2000 hsy.googlegroups.com...
On Nov 28, 12:43 pm, "Jonathan Wood" <jw...@softcircuits.comwrote:
>Larry,


>I don't want the overhead of returning a dataset and then getting the
number
of items in it. I'd like to create a stored procedure for maximum
efficiency
that returns the number of users in a particular role.
>It appears that role IDs are encrypted in the membership tables so I'm
not
really sure where to start. I was hoping this wouldn't be that
complicated
as I'm pretty new to this.
>Thanks for any tips.
Very simple. No need for a stored procedure...
Imports System.Web.Security
dim count as integer = roles.GetUsersInRole("rolename").Length

Perhaps I'm missing something here.

My understanding is that, not only does this approach load the entire
dataset of users of a particular role into memory, it then makes a second
copy of that data in an in-memory collection, before finally getting the
number of items in that collection. This strikes me as horribly
inefficent,
and would not meet my stated objectives.

I cannot comment on how it works, sorry, but I doubt they'd go through
the trouble of making all these functions that are so inefficient as
to be useless.

Maybe a Microsoft guy can chime in.

Nov 29 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ferherra | last post by:
Hi, Hope someone can help... I databind my gridview (asp.net 2.0) like this: GridView1.DataSource = Membership.GetAllUsers(); (MembershipUserCollection) GridView1.DataBind(); In the...
1
by: Microsoft News Group | last post by:
I am setting up a customer portal. I am setting up users, and then deleting them. But if I set up a user with the same name I deleted. Then I get this error. The user 'Flynn' is already in...
4
by: =?Utf-8?B?Q2hyaXMgQ2Fw?= | last post by:
I have been having some trouble with implementing a custom Membership Provider. We have a custom data store and business logic that pulls user information. I need some level of functionality...
0
by: Douglas J. Badin | last post by:
Hi, The problem with Authorization is it stops at the first match and doesn't permit Grouping. On the Web Site, I am trying to Secure Page Access and SiteNaviagation by implementing the...
0
by: awrigley | last post by:
Hi An app that was chuntering away quite happily to itself had roles added to it. Just two: Admins and Subscribers. However, I seem to have mucked up when assigning the role provider in the...
3
by: Steven Nagy | last post by:
Hi all, I'm getting across the membership API stuff. However it seems that we would have benefitted from some extra controls for "Manage Users" and "Manage Roles". Is there some additional...
1
by: kpg* | last post by:
Hi all, Trying to use the ASP.NET 2.0 membeship API to manage users and user profiles, and of course, to provide role based security to my web app. I have several attributes I want to users,...
4
by: alexandis | last post by:
There are tons of articles about custom role and provider membership, but they just tear me apart and confuse :( The situation is following: I use DB2, so I wrote custom role + membership...
9
by: Jonathan Wood | last post by:
I've spent days trying to come up with a solution. I'd appreciate it if anyone can help. My site requires all users to log on. There are three different roles of users, and each user type will...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.