Print Page | Close Window

Customer MembershipProvider

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2552
Printed Date: 16-Apr-2024 at 1:31am


Topic: Customer MembershipProvider
Posted By: rlejeune
Subject: Customer MembershipProvider
Date 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



Replies:
Posted By: DenisK
Date 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.


Posted By: DenisK
Date 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.


Posted By: rlejeune
Date 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


Posted By: DenisK
Date 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.



Print Page | Close Window