Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created June 13, 2012 19:14
Show Gist options
  • Select an option

  • Save mgroves/2925880 to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/2925880 to your computer and use it in GitHub Desktop.
postsharp with MVC
using System;
using System.Web.Mvc;
using PostSharp.Aspects;
namespace MvcApplication1WithPostSharp.Controllers
{
public class HomeController : Controller
{
[MyExitAspect]
public ActionResult Index()
{
Session["stuff"] = DateTime.Now.ToString();
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
}
[Serializable]
public class MyExitAspect : OnMethodBoundaryAspect
{
public override void OnExit(MethodExecutionArgs args)
{
var controller = args.Instance as Controller;
if (controller != null)
{
var session = controller.HttpContext.Session;
controller.Response.Write(session["stuff"]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment