Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TrackActionFilterAttribute : ActionFilterAttribute, IActionFilter
- {
- public override void OnActionExecuting(ActionExecutingContext filterContext)
- {
- Tracking track = new Tracking()
- {
- Action = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName + filterContext.ActionDescriptor.ActionName
- };
- context.Trackings.Add(track);
- context.SaveChanges();
- }
- }
- [TrackActionFilter]
- public ActionResult Index()
- {
- if (Request.Form["registered"] == 1)
- return PartialView("Landing");
- else
- return PartialView("Register");
- }
- [TrackActionFilter]
- public ActionResult Landing()
- {
- return PartialView();
- }
- [TrackActionFilter]
- public ActionResult Register()
- {
- return PartialView();
- }
- filterContext.HttpContext.Request["registered"]
- public override void OnActionExecuted(ActionExecutedContext filterContext)
- {
- var viewResult = filterContext.Result as ViewResultBase;
- if (viewResult != null)
- {
- // the controller action returned either a View or a partialView
- // => we could get its name:
- var name = viewResult.ViewName;
- }
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement