【问题标题】:WCF membership providerWCF 成员资格提供程序
【发布时间】:2011-02-02 10:59:59
【问题描述】:

我有一个使用用户名凭据的 WCF 服务。现在 System.Web.Security.Membership.GetUser 总是返回 null 但它能够提取 aspnetdb 中的用户列表 (System.Web.Security.Membership.GetAllUsers())

但在服务端,“ServiceSecurityContext.Current.PrimaryIdentity.Name”始终返回正确的经过身份验证的用户名。

有人知道为什么 GetUser() 总是返回 null 吗?

这是来自 sql profiler 的跟踪

exec dbo.aspnet_Membership_GetUserByName @ApplicationName=N'myApplication',@UserName=N'',@UpdateLastActivity=1,@CurrentTimeUtc='2011-02-01 23:14:56.2830000'

注意上面的用户名是空白的。

【问题讨论】:

  • 您确定有用户登录...
  • 是.. 用户已通过身份验证.. 如果不是,“ServiceSecurityContext.Current.PrimaryIdentity.Name”将不会返回正确的用户名,不是吗?

标签: .net asp.net wcf


【解决方案1】:

我过去也遇到过类似的问题,在我的情况下,将我的代码更改为以下代码解决了这个问题:

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;  

我从以下帖子中得到了这个提示: http://forums.asp.net/p/939408/1316031.aspx

希望其中的一个答案也对你有用。

干杯!

【讨论】:

    猜你喜欢
    • 2011-03-19
    • 2010-12-14
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 2010-11-15
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    相关资源
    最近更新 更多