WCF membership provider
I have a WCF service using username credentials. Now the System.Web.Security.Membership.GetUser always returns null but it is able to extract the list of user in aspnetdb (System.Web.Security.Membership.GetAllUsers())
However on the service side the "ServiceSecurityContext.Current.PrimaryIdentity.Name" always returns the correct authenticated username.
does anyone know why the GetUser() always return null?
this is the trace from sql profiler
exec dbo.aspnet_Membership_GetUserByName @ApplicationName=N'myApplication',@UserName=N'',@UpdateLastActivity=1,@CurrentTimeUtc='2011-02-01 2开发者_如何学Python3:14:56.2830000'
Notice that the above username is blank.
I had similar problem in the past, and in my case, changing my code to the below snipped fixed the issue:
MembershipUser user = Membership.GetUser(username);
GenericIdentity identity = new GenericIdentity(user.UserName);
RolePrincipal principal = new RolePrincipal(identity);
System.Threading.Thread.CurrentPrincipal = principal;
HttpContext.Current.User = principal;
I've got this tip from the following thread: http://forums.asp.net/p/939408/1316031.aspx
Hope one of the answers there works for you as well.
Cheers!
精彩评论