New Posts New Posts RSS Feed: Customer MembershipProvider
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Customer MembershipProvider

 Post Reply Post Reply
Author
rlejeune View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Feb-2011
Location: Male
Posts: 2
Post Options Post Options   Quote rlejeune Quote  Post ReplyReply Direct Link To This Post Topic: Customer MembershipProvider
    Posted: 10-Mar-2011 at 3:50pm
I've implemented a simple MembershipProvider and I'm only implementing the ValidateUser method.  When the method is called I get the following error:
 
An EntityManager can only execute on a single thread. This EntityManager is authorized to execute on the thread with id=’12’; the requested operation came from the thread with Id=‘10’.
Consider calling the EntityManager’s asynchronous methods; they work safely on background threads managed by DevForce.
You may have to disable this cross-thread checking for specific reasons such as automated testing. Please review our documentation on multi-threading issues and the EntityManager.AuthorizedThreadId property.
 
Here is the Method: 

public override bool ValidateUser(string username, string password){
ACTContext _dc = new ACTContext();
var query = _dc.actMembers.Where(m => m.UserName == username && m.Password == password);
bool flag = false;
_dc.ExecuteQueryAsync(query, (s) => {s.Completed += (o, args) => {
  if (args.HasError)args.MarkErrorAsHandled();
  if (args.Results != null)
  flag = true;
};
});
return flag;}
 
What am I missing?
 
RL
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 10-Mar-2011 at 7:12pm
Hi rlejeune;

I don't see anything wrong in this code. I might have to see the whole solution. Would you be able to upload it here? Thanks.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 10-Mar-2011 at 7:46pm
Hi rlejeune;

Actually, after looking at it closer, it looks to be a threading issue with the async operation. Since ASP.NET does not have the same threading model as SL and Windows, I think you're fine with setting your EntityManager.AuthorizedThreadId to null here.

Also, it's probably not necessary to do an async operation here since ValidateUser itself is a sync call on the server.

I also want to remind you to not use the same "ACTContext" EntityManager on your client app since the EntityManager will always try to login and possibly causing strange circularity problems.


Edited by DenisK - 10-Mar-2011 at 7:48pm
Back to Top
rlejeune View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Feb-2011
Location: Male
Posts: 2
Post Options Post Options   Quote rlejeune Quote  Post ReplyReply Direct Link To This Post Posted: 11-Mar-2011 at 1:01pm
What a brain breakdown I had not even thinking about the Async on the Server which makes perfect sence - thanks for that catch.
 
So if I'm not to use the same EntityManager for both Client and Server - do I have to create another EntityModel?
 
 
Thanks,
RL
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 11-Mar-2011 at 2:09pm
Yes. I should probably rephrase my statement for clarity. You should not use "ACTContext" EM to deal with your app's business objects. You should separate the 2, i.e. one for your custom membership provider and one for your app's business objects.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down