3

우리는 Silverlight 5 프로젝트와 함께 WCF Ria Services를 사용하고 있습니다. 인증을 위해 RIA Services 클래스 라이브러리에서 맞춤 멤버쉽 공급자 WCF Ria Service를 사용하고 있습니다. 클라이언트 측 인증 실행 중 .WebContext.Current.User.Name.But 서버 측 ServiceContext.User 비어있는 현재 사용자 이름에 액세스합니다. [RequireAuthentication] attr을 사용하는 경우. DomainServices에서 항상 Access Denied를 반환합니다. 어떻게 WebContext.Current.user를 ServiceContext.user로 푸시 할 수 있습니까? 여러 문서 및 자습서를 읽었지만 모든 테스트가 실패합니다.WCF RIA 서비스 양식 인증 ServiceContext.User.Identity.Name 비어 있습니다.

코드 예제 :

있는 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); 

답변

2

나는 똑같은 문제를 겪고 있었지만 마침내 답을 찾아 냈습니다. SOAP 종점을 노출하려고 애 쓰고 있었기 때문에 전화 앱에서 동일한 RIA 서비스에 액세스 할 수있었습니다. 그 일환으로 App 생성자에 다음 줄을 추가했습니다.

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

제거하고 사용자 이름을 다시 사용할 수있게해야합니다. SOAP 종점은 여전히 ​​전화 앱에도 노출되어있는 것처럼 보입니다.

0

WCF RIA 서비스를 사용하는지 여부에 관계없이 처음에는 호스팅 웹 사이트에 대해 configure Forms authentication을 사용해야합니다. 또한 폼 인증을 설치하고 enabled on IIS을 설치해야합니다.

클래스를 사용하려면 ASP.NET membership을 구성해야합니다.