我們正在使用WCF RIA服務與我們在RIA服務類庫使用自定義會員provider.WCF地頭服務的Silverlight 5 project.For認證。 客戶端認證running.We使用WebContext.Current.User.Name.But訪問當前用戶名,但服務器端ServiceContext.User爲空。如果我們使用[RequireAuthentication] attr。在DomainServices中總是返回拒絕訪問。 我們如何推送WebContext.Current.user到ServiceContext.user.I閱讀幾個文檔和教程,但每個測試都失敗。WCF RIA Services表單驗證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);