Created
June 13, 2012 19:14
-
-
Save mgroves/2925880 to your computer and use it in GitHub Desktop.
postsharp with MVC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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