1

我在SL4業務應用程序中使用自定義MembershipProvider(使用EF而不是Sql)。如何在Silverlight 4 Business Application中獲取當前用戶的電子郵件?

MembershipUser類的默認實現有一個電子郵件地址屬性,但是由SL4商務應用模板(從UserBase繼承)定義的User對象不給你訪問電子郵件屬性。

而且當AuthenticationService(繼承自AuthenticationBase<User>)甚至不嘗試讀取用戶的電子郵件。

有沒有辦法通過使用AuthenticationService訪問MembershipUser(服務器端)/用戶(客戶端)的Email屬性,還是我必須創建我自己的例程來返回用戶的正確屬性?

感謝,

馬丁

回答

1

可以,只要你實現IUSER創建自己的用戶類。

public class User : IUser 
{ 
    public int Id { get; set; } 

    public string UserName { get; set; } 
    public string Password { get; set; } 
    public string Email { get; set; } 

    #region Implementation of IUser 
    public string Name { get; set; } 
    public IEnumerable<string> Roles { get; set; } 
    #endregion 
} 

您可以修改AuthenticationService來實現IAuthentication<User>並實施登錄。作爲您實施的Login流程的一部分,您可以填充User.Email

public class AuthenticationService : DomainService, IAuthentication<User> 
{ 
     public User Login(string userName, string password, bool isPersistent, string customData) 
     { 
      //can populate User.Email on successful login. 
     } 
} 
+0

但問題是,'AuthenticationBase '已經實現了'登錄()'方法,但因爲它是在'IAuthentication '接口中聲明它沒有聲明爲虛。我可以使用新的操作員來隱藏它嗎?在'公共新用戶登錄(字符串用戶名,字符串密碼,布爾isPersistent,字符串customData)'? – bleepzter

+0

嗯,我只是試過,並沒有奏效。您無法隱藏基礎DomainService類的方法。所以這裏的答案略有不同。將該電子郵件添加爲Web.config中的配置文件屬性,將其作爲自動屬性添加到User對象,最後覆蓋'AuthenticationBase '的'protected override void UpdateUserCore(User user)'方法,以便它將更新成員用戶中的電子郵件。 – bleepzter

+0

那麼,你不想實現登錄?這是問題嗎?我使用我發佈的解決方案來使用IpAddress填充用戶,以便在客戶端可用。 –

相關問題