Asp.net mvc 4 如何在同一解决方案中的项目之间持久化HttpContext.Current?
我对形式认证的概念还不熟悉,我正在努力解决一些问题 我有一个MVC4项目MyApp.Web,它有一个带有登录方法的AccountController:Asp.net mvc 4 如何在同一解决方案中的项目之间持久化HttpContext.Current?,asp.net-mvc-4,httpcontext,formsauthentication,Asp.net Mvc 4,Httpcontext,Formsauthentication,我对形式认证的概念还不熟悉,我正在努力解决一些问题 我有一个MVC4项目MyApp.Web,它有一个带有登录方法的AccountController: public ActionResult Login(LoginModel model, string returnUrl) { string siteName = ConfigurationManager.AppSettings["siteName"]; if (ModelState.IsValid && Mem
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时,我在主方法HttpContext中放置了一个断点。Current与我的会员项目中的断点不同;我在Login方法中设置的值都没有保留
那么,简单地说,我如何确保它们是相同的,并在HttpContext.Current上设置值。一个项目中的当前值将传递到同一解决方案中的任何其他项目
谢谢