日期:2014-05-17 浏览次数:20546 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVCSession.Controllers
{
public class TestController : Controller
{
public ActionResult Index()
{
string sessionData = "Now "+DateTime.Now.ToString();
HttpContext.Session["Data"] = sessionData;
return Content(string.Format("SessionID={0}\nSession={1}\n", HttpContext.Session.SessionID, sessionData), "text/txt");
}
public ActionResult GetSession()
{
string sessionData = (string)HttpContext.Session["Data"];
return Content(string.Format("SessionID={0}\nSession={1}\n", HttpContext.Session.SessionID,sessionData== null ? "Null" : sessionData, "text/txt"));
}
}
}