私は FormsAuthentication の概念に不慣れで、何かに苦労しています。
Login メソッドを持つ AccountController を持つ MVC4 プロジェクト MyApp.Web があります。
public ActionResult Login(LoginModel model, string returnUrl)
{
string siteName = ConfigurationManager.AppSettings["siteName"];
if (ModelState.IsValid && MembershipService.Login(model.UserName, model.Password, siteName))
{
return RedirectToAction("Main", "Home");
}
}
MembershipService は別のプロジェクトにあります (クラス ライブラリ)
public bool Login(string username, string password, string site)
{
// ....
// do the validation, set up my ClaimsPrincipal and create a FormsAuthenticationTicket,
// which is stored in the Cookies collection
// now, we can save the ClaimsPrincipal to the relevant place
if (HttpContext.Current != null && HttpContext.Current.User != null)
HttpContext.Current.User = claimsPrincipal;
else if (Thread.CurrentPrincipal != null)
Thread.CurrentPrincipal = claimsPrincipal;
return success;
}
すべてが完全に機能しているように見えます。必要に応じて検証され、ClaimsPrincipal が作成されて保存されます。
私の問題は、MyApp.Web にリダイレクトされて HomeController に戻り、Main メソッドにブレークポイントを設定すると、HttpContext.Current がメンバーシップ プロジェクトのものと同じではないことです。Login メソッドで設定した値はどれも保持されていません。
では、簡単に言えば、それらが同じであり、あるプロジェクトの HttpContext.Current の設定値が同じソリューション内の他のプロジェクトに引き継がれるようにするにはどうすればよいでしょうか?
ありがとう