我在UsersController和Login Called AterLogin中有一个ActionResult登录,它位于NEWSController.Now中,我想读一个在Login中创建的Session。 登录代码:
public ActionResult Login(Users U)
{
if (ModelState.IsValid)
{
using (NEWSDBContext DB = new NEWSDBContext())
{
var v = DB.Userss.Where(a => a.UserName.Equals(U.UserName
&& a.PassWord.Equals(U.PassWord)).FirstOrDefault();`
if (v != null)
{
Session["LogedUserID"] = v.UserID.ToString();
Session["LogedUserFullname"] = v.Name.ToString() + " " + v.Family.ToString();
return RedirectToAction("AfterLogin","NEWS");
}
}
}
return View(U);
}
AfterLogin代码:
public ActionResult AfterLogin()
{
int id = int.Parse(Session["LogedUserID"].ToString());
NEWS news = db.NEWSs.Find(id);
return View(news);
}