3

We are using WCF Ria Services with silverlight 5 project.For authentication we are using Custom membership provider.WCF Ria Service in RIA Services class library. Client side authentication running.We access current user name with WebContext.Current.User.Name.But server side ServiceContext.User empty.If we use [RequireAuthentication] attr. in DomainServices return always Access Denied. How Can we push WebContext.Current.user to ServiceContext.user.I read several document and tutorial but every test fail.

Code examples :

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;
        }
    }

}

AuthenticationDomainService:

      [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);
ctoker
  • 31
  • 2

2 Answers2

2

I was having the same problem, but I have finally tracked down the answer. I had been messing about trying to expose SOAP endpoints, so I could access the same RIA services from a phone app. As part of that, I had added the following line in the App constructor:

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

Get rid of that, and you should have the user name available again. SOAP endpoints still seem to be exposed to the phone app as well.

john_cat
  • 354
  • 2
  • 8
0

At first you have to configure Forms authentication for your hosting website regardless whether you use WCF RIA Service or not. Moreover, Forms authentication have to be installed and enabled on IIS.

Then you have to configure ASP.NET membership in order to use your CustomMembershipProvider class.

Jozef Benikovský
  • 1,121
  • 10
  • 9