I'm trying to send a mail to all users in a specific role. So I need to get all users in that role. I got this code
public static void SendToAllUsersInRole(string role, string subject, string body)
{
var usersInRole = Roles.GetUsersInRole(role);
var users = Membership.GetAllUsers().Cast<MembershipUser>().Where(u => !usersInRole.Contains(u.UserName));
When I try this code I get the error The role 'Test' was not found.Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Configuration.Provider.ProviderException: The role 'Test' was not found. Source Error:
Line 44: public static void SendToAllUsersInRole(string role, string subject, string body)
Line 45: {
Line 46: var usersInRole = Roles.GetUsersInRole(role); Line 47: var users = Membership.GetAllUsers().Cast<MembershipUser>().Where(u => !usersInRole.Contains(u.UserName));
Line 48:
I have the role "Test" in my db. I have the roles Admin, Member and Test and I get the same error for all roles the role Admin was not found and so on.
When I try if(User.IsInRole("Admin")) then it works great. Do you have abny suggestions for me?
svetsarn
Member
487 Points
612 Posts
Can't find role
Jan 08, 2013 01:36 AM|LINK
I'm trying to send a mail to all users in a specific role. So I need to get all users in that role. I got this code
public static void SendToAllUsersInRole(string role, string subject, string body) { var usersInRole = Roles.GetUsersInRole(role); var users = Membership.GetAllUsers().Cast<MembershipUser>().Where(u => !usersInRole.Contains(u.UserName));When I try this code I get the error
The role 'Test' was not found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Configuration.Provider.ProviderException: The role 'Test' was not found.
Source Error:
Line 44: public static void SendToAllUsersInRole(string role, string subject, string body) Line 45: { Line 46: var usersInRole = Roles.GetUsersInRole(role);Line 47: var users = Membership.GetAllUsers().Cast<MembershipUser>().Where(u => !usersInRole.Contains(u.UserName)); Line 48:
I have the role "Test" in my db. I have the roles Admin, Member and Test and I get the same error for all roles the role Admin was not found and so on.
When I try if(User.IsInRole("Admin")) then it works great. Do you have abny suggestions for me?
ignatandrei
All-Star
134983 Points
21638 Posts
Moderator
MVP
Re: Can't find role
Jan 08, 2013 01:40 AM|LINK
Start Sql Server profiler ( SSMS, Tools, Sql Server PRofiler) and see the query
svetsarn
Member
487 Points
612 Posts
Re: Can't find role
Jan 08, 2013 01:48 AM|LINK
I can't find the Sql Server Profiler in SQL Server Managment Studio :(
ignatandrei
All-Star
134983 Points
21638 Posts
Moderator
MVP
Re: Can't find role
Jan 08, 2013 02:02 AM|LINK
then what is your connection string in web.config?
svetsarn
Member
487 Points
612 Posts
Re: Can't find role
Jan 08, 2013 02:05 AM|LINK
ignatandrei
All-Star
134983 Points
21638 Posts
Moderator
MVP
Re: Can't find role
Jan 08, 2013 06:58 AM|LINK
please tell also
tagsvetsarn
Member
487 Points
612 Posts
Re: Can't find role
Jan 08, 2013 07:52 AM|LINK
I don't have the membership-tag.