1

SL4ビジネスアプリケーションでカスタムMembershipProvider(SqlではなくEFを使用)を使用しています。Silverlight 4 Business Applicationで現在のユーザーの電子メールを取得するにはどうすればよいですか?

MembershipUserクラスのデフォルトの実装は、しかし、あなたは電子メールのプロパティにはアクセスできません(UserBaseから継承)SL4ビジネスアプリケーションテンプレートで定義されたUserオブジェクトを電子メールアドレスのプロパティがあります。

さらに、AuthenticationServiceAuthenticationBase<User>から継承)でもユーザーの電子メールを読み取ろうとしないとき。

AuthenticationServiceを使用してMembershipUser(サーバー側)/ User(クライアント側)のEmailプロパティにアクセスする方法はありますか、ユーザーの正しいプロパティを返すように独自のルーチンを作成する必要はありますか?

おかげで、

マーティン

答えて

1

あなたがいる限り、あなたがたIUserの実装として、独自のUserクラスを作成することができます。

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 
} 

あなたはIAuthentication<User>を実装し、ログインを実装するためにAuthenticationServiceを変更することができます。実装された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 'インタフェースで宣言されているため、それを仮想として宣言されていないということです。新しい演算子を使用してそれを隠すことはできますか? 'public user login(string userName、string password、bool isPersistent、string customData)'のように? – bleepzter

+0

さて、私はこれを試したところ、うまくいかなかった。ベースのDomainServiceクラスのメソッドを非表示にすることはできません。したがって、ここの答えは少し異なります。電子メールをWeb.configのプロファイルプロパティとして追加し、自動プロパティとしてUserオブジェクトに追加し、最終的に 'AuthenticationBase 'の 'protected override void UpdateUserCore(User user)'メソッドをオーバーライドして更新しますメンバーシップユーザーの電子メール。 – bleepzter

+0

ログインを実装する必要はありませんか?それは問題ですか?私はIpAddressを使ってUserを実装するために投稿したソリューションを使用して、クライアントで利用できるようにします。 –