This project is read-only.

How I will have my code called every time a visitor opens any page?

Topics: General, Writing modules
Feb 27, 2013 at 1:24 PM
Hi, I created a module that performs a few tasks and are transparent to the visitor.
The question is how I will have my code called every time a visitor opens any page?

I found some other posts, that says you can achieve this by extending IOrchardShellEvents. So I made a class that extents this interface in my module, implement its method and put breakpoints on Activated but when I enter the website it was not executed.

Any suggestions are welcome.
Feb 27, 2013 at 2:00 PM
If you trace back from where that method is being called, you'll see why it's not being called on each request.
What you could do instead is implement a class that derives from FilterProvider and implement IActionFilter. Now your code will run on each request.
Feb 27, 2013 at 2:23 PM
Thanks for your immediate answer, this is what I was looking for. :)
Below is the code for anyone that might be interested.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Orchard;
using Orchard.Mvc;
using Orchard.Mvc.Filters;
using IFilterProvider = Orchard.Mvc.Filters.IFilterProvider;

namespace MyNamespace.Filters
    public class MyFilter : FilterProvider, IActionFilter {
        private readonly IOrchardServices _orchardServices;
        private readonly Lazy<IEnumerable<IFilterProvider>> _filterProviders;
        private CookieService _cookie;

        public MyFilter (IOrchardServices orchardServices, Lazy<IEnumerable<IFilterProvider>> filters)
            _filterProviders = filters;            
            _orchardServices = orchardServices;
        public void  OnActionExecuted(ActionExecutedContext filterContext)

        public void  OnActionExecuting(ActionExecutingContext filterContext)

Mar 3, 2013 at 12:48 AM
The Voting module provides some useful APIs IIRC.
Mar 3, 2013 at 8:19 AM
thanks, I will take a look. :)