Neill
Neill

Reputation: 711

Using ASP.net membership to get aspnet_Users in silverlight

Hope somebody can help.

Have looked around on the net but cannot seem to solve (or understand) this.

I have tried the code posted at

http://blogs.msdn.com/b/kylemc/archive/2010/05/10/using-asp-net-membership-in-silverlight.aspx (not going to repeat the class MembershipServiceUser here as it is quite long and can be seen on the mentioned page)

I have set up the domain service with the class and the code to return the users:

//[RequiresRole("Managers")]
public IEnumerable<MembershipServiceUser> GetAllUsers()
{
    return Membership.GetAllUsers().Cast<MembershipUser>().Select(u => new MembershipServiceUser(u));

}

I took out the RequiresRole for testing.

What I seem to be a bit blonde about is the calling of the GetAllUsers() method.

In my code behind I am using:

MembershipDataContext context = new MembershipDataContext();
EntityQuery<MembershipServiceUser> users = context.GetAllUsersQuery(); 

I am not 100% sure if this is the correct way to use the method or if something else is wrong because

context.GetAllUsersQuery(); returns "Enumeration yielded no results"

One question is also in the code kylmc uses //RequiresRole("Admin")]. Is this a custom role created in the ASP.NET Configuration editor?

Looking at another tutorial regarding using the ASP.NET authentication service in Silverlight, I create a role called "Managers" and added the login user to that role. Logging in using a user with role Managers doesn't help and results are still not yielded.

Any ideas I could possible look at?

Many thanks

Neill

Upvotes: 1

Views: 515

Answers (1)

Chui Tey
Chui Tey

Reputation: 5564

There are two steps involved with querying.

  1. Get a query object from the Domain Service context (synchronous).
  2. Load the query from the Domain Service context (asynchronous).

Example:

public void Load()
{
  // define the query
  var query = context.GetAllUsersQuery();

  // start running the query, and when the results return call
  // OnGetAllUsersLoaded
  context.Load(query, OnGetAllUsersLoaded, null);
}

public void OnGetAllUsersLoaded(LoadOperation op)
{
  var results = op.Entities;
}

Upvotes: 1

Related Questions