Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt Jones 30 posts 141 karma points
    May 01, 2013 @ 21:58
    Matt Jones
    0

    MVC Register Global Filter -Umbraco 6.04

    Hi

    I'm trying to register a global filter in global.asax, I basically just want some code to run on every page to check some session variables, so if anyone knows a better way of doing it that would be great...

    I've followed the same principal as registering routes but my code in my overriden  OnApplicationStarted never seems to get executed

    this is the contents of global.asax.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    using System.Web.Security;
    using System.Web.SessionState;
    using MyApp.Filters;

    namespace MyApp
    {
        public class MyApp : Umbraco.Web.UmbracoApplication
        {

            public static void RegisterGlobalFilters(GlobalFilterCollection filters)
            {
                filters.Add(new HandleErrorAttribute());
            }
           
            protected override void OnApplicationStarted(object sender, EventArgs e)
            {
                base.OnApplicationStarted(sender, e);
               
                GlobalFilters.Filters.Add(new SessionActionFilterAttribute());
                RegisterGlobalFilters(GlobalFilters.Filters);        

            }              
        }
    }
  • Matt Jones 30 posts 141 karma points
    May 02, 2013 @ 13:42
    Matt Jones
    101

    I got this to work in the end, I was already using StructureMap for dependency injection of an interface to some external data models, StructureMap had created a

    class in the App_Start folder with a Start() method so i moved my RegisterGlobalFilters method to this class and added the filters in the Start() method.

    In my ActionFilter class I'm overriding OnActionExecuting instead of OnResultExecuting  - but i'm not sure which is right here....

Please Sign in or register to post replies

Write your reply to:

Draft