asp.net mvc中session的使用 样例

给Session赋值:Session["session名字"]=要赋给Session的值
读取Session的值:要得到的数据类型 变量=(要得到的数据类型)Session["session名字"];
public class HomeController : Controller
{
public ActionResult Index( )
{
ViewBag.Message = "欢迎使用 ASP.NET MVC!";
Session[ "KeyName" ] = "Test";
return View( );
}

public ActionResult About( )
{
if ( Session[ "KeyName" ] != null )
{
ViewBag.Message = Session[ "KeyName" ];
}
return View( );
}
}
posted @ 2012-12-11 09:09  Raywang80s  阅读(566)  评论(0编辑  收藏  举报