forms-authentication - WCF RIA 服务表单例份验证 ServiceContext.User.Identity.Name 空

标签 forms-authentication wcf-ria-services silverlight-5.0 custom-membershipprovider

我们正在将 WCF Ria 服务与 silverlight 5 项目结合使用。对于身份验证,我们使用自定义成员资格提供程序。RIA 服务类库中的 WCF Ria 服务。 客户端身份验证正在运行。我们使用 WebContext.Current.User.Name 访问当前用户名。但是服务器端 ServiceContext.User 为空。如果我们使用 [RequireAuthentication] attr。在 DomainServices 中返回始终拒绝访问。 我们如何将 WebContext.Current.user 推送到 ServiceContext.user。我阅读了几个文档和教程,但每个测试都失败。

代码示例:

CustomMembershipProvider.cs:

   public class CustomMembershipProvider : MembershipProvider    {
    public override bool ValidateUser(string username, string password)
    {
        using (var context = new TimEntities())
        {
            var user = context.User.FirstOrDefault(u => u.Username == username &&
                                                         u.Password == password);
            return user != null;
        }
    }

}

身份验证域服务:

      [EnableClientAccess]
      public class AuthenticationDomainService : AuthenticationBase<AuthUser>
      {}
      public class AuthUser : UserBase
      {}

App.Xaml.Cs:

  var webContext = new WebContext();
  var formsAuth = new FormsAuthentication();
  var authContext = new AuthenticationDomainContext();
  formsAuth.DomainContext = authContext;
  webContext.Authentication = formsAuth;
  ApplicationLifetimeObjects.Add(webContext);

最佳答案

我也遇到了同样的问题,不过终于找到答案了。我一直在尝试公开 SOAP 端点,这样我就可以从手机应用程序访问相同的 RIA 服务。作为其中的一部分,我在 App 构造函数中添加了以下行:

WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);

去掉它,您应该可以再次使用该用户名。 SOAP 端点似乎仍然暴露给手机应用程序。

关于forms-authentication - WCF RIA 服务表单例份验证 ServiceContext.User.Identity.Name 空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12671740/

相关文章:

asp.net-mvc - 在 Web 层之外获取当前的 Principal

c# - ASP.NET 混合身份验证

silverlight - POCO 的 WCF RIA 服务作为查询参数

c# - 如何将非托管 C++ dll 添加到 Silverlight 5 项目中

vb.net - 如何构建将音频文件下载到本地文件夹或从Silverlight应用程序下载文件夹的功能?

c# - 验证请求事件

sql-server - 如何将带外(当前用户 ID)数据传递给 SQL Server 2008

silverlight-4.0 - 自定义 WCF RIA 服务终结点

entity-framework - CQRS与 Entity Framework 自跟踪实体/WCF RIA服务兼容吗?

c# - 添加服务引用总是生成 xmlserializer 而不是 DataContractSerializer