简体   繁体   English

WCF会员资格提供者

[英]WCF membership provider

I have a WCF service using username credentials. 我有一个使用用户名凭据的WCF服务。 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()) 现在,System.Web.Security.Membership.GetUser始终返回null,但是它能够提取aspnetdb中的用户列表(System.Web.Security.Membership.GetAllUsers())

However on the service side the "ServiceSecurityContext.Current.PrimaryIdentity.Name" always returns the correct authenticated username. 但是,在服务端,“ ServiceSecurityContext.Current.PrimaryIdentity.Name”始终返回正确的经过身份验证的用户名。

does anyone know why the GetUser() always return null? 有谁知道为什么GetUser()总是返回null?

this is the trace from sql profiler 这是来自SQL Profiler的跟踪

exec dbo.aspnet_Membership_GetUserByName @ApplicationName=N'myApplication',@UserName=N'',@UpdateLastActivity=1,@CurrentTimeUtc='2011-02-01 23:14:56.2830000' exec dbo.aspnet_Membership_GetUserByName @ ApplicationName = N'myApplication',@ UserName = N'',@ UpdateLastActivity = 1,@ CurrentTimeUtc ='2011-02-01 23: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 我从以下线程获得了提示: http : //forums.asp.net/p/939408/1316031.aspx

Hope one of the answers there works for you as well. 希望那里的答案之一也对您有用。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM