3
我正在写一个asp.net MVC 2.0应用程序,我需要在用户登录后将用户名传递给其他函数。我想,通过简单修改了的AccountController标准的登录方法,这里是我的代码:登录后,为什么user.Identity.Name为空? Asp.net mvc 2.0
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
using (ShopController newCtrl = new ShopController())
{
if (Session["TempCart"] != null)
{
newCtrl.CreateShoppingCartFromSession((Cart)Session["TempCart"], User.Identity.Name);
}
}
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
的问题是,即使用户成功登录,则“User.Identity.Name”是空白,我不知道为什么...
任何帮助将不胜感激。