Webサービスからのユーザーに関するトラック全体の情報を保存しようとしています。これは現在認証されているユーザーに関する情報であるため、その情報をカスタムIIdentity実装に保存することは理にかなっていると思いました。
カスタムはWebサービスを呼び出し、すべてのフィールド(部門、電話番号、その他の従業員情報)が入力されMagicMembershipProvider.GetUser(string id, bool userIsOnline)
たインスタンスを返します。MagicMembershipUser
カスタムメンバーシッププロバイダーとカスタムメンバーシップユーザーはどちらも正常に機能します。
すべてのコントローラーでアクセス可能なオブジェクトにメンバーシップユーザー情報を配置するための最良の方法はどこにありますか?IPrincipal User
私は、MVC2アプリケーションでIIdentity、IPrincipal、およびRoleの承認を使用して、セキュリティのプログラムフローに頭を悩ませようとしてきましたが、ここでは本当に苦労しており、メンタリングを使用できます。部分についての記事のインターネットトンがありますが、全体についてはあまりありません。
編集
これまでの私の最善の推測はHttpContext.Current.User
、FormsAuthenticationService
:にを割り当てることです。
public void SignIn(string userName, bool createPersistentCookie)
{
if (String.IsNullOrEmpty(userName))
throw new ArgumentException("Value cannot be null or empty.", "userName");
try
{
FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
MagicMembershipUser magicUser = _provider.GetUser("", false)
as MagicMembershipUser;
MagicIdentity identity = new MagicIdentity(userName, magicUser);
GenericPrincipal principal = new GenericPrincipal(identity, null);
HttpContext.Current.User = principal;
}
catch (Exception)
{
throw;
}
}