public class MyController : Controller { public ActionResult Index() { var context = HttpContext; // Do something with the HttpContext object return View(); } }
public class MyController : Controller { public ActionResult Index() { TempData["message"] = "Hello world!"; return View(); } }Both of these examples show how ControllerContext can be used to interact with the current request being handled by an ASP.NET MVC controller. The ControllerContext class is part of the System.Web.Mvc package library.