MVC開発プログラムにおけるセッションの使い方
3810 ワード
public class UserBF
{
private masterDataContext _Context = new masterDataContext();
public bool Login(string users,string pass)
{
var query = _Context.denglu.Where(p => p.users == users && p.pass == pass);
return query.Count() > 0;
}
}
public ActionResult Checkuidpwd(string uid,string pwd)
{
bool isok = new UserBF().Login(uid,pwd);
if (isok == true)
{
//
// Session
Session["user"] = uid;
//
return RedirectToAction("Index","Home");
}
else
{
return RedirectToAction("Index");
}
}
public ActionResult Index()
{
// session , , 。
if (Session==null)
{
return RedirectToAction("index","login");
}
return View();
}
<div> :@Session["user"].ToString()</div>