Question

I have made a custom filter that is to fire on every action(request). So what the issue seems to be is that thou the first time the action runs when the user refreshes it never runs again. It's like it's cached or something. I does fire the filter the first time so the code is working(-ish) but it's the secound loadin of the page that is killing me. here is basicly the code.

        using MonoRailHelper;
        namespace evergreen.Controllers
        {

            public class loggedinFilterAttribute : FilterAttribute
            {
                public loggedinFilterAttribute() : base ( ExecuteEnum.BeforeAction, typeof(AuthenticationFilter))
                {

                    String username = Authentication.authenticate();
                    // save user in database
                    authUser[] authUser_list = ActiveRecordBase<authUser>.FindAll();
                    authUser temp = null;
                    foreach (authUser authUser in authUser_list)
                    {
                        if (!string.IsNullOrEmpty(authUser.Nid) && authUser.Nid.ToUpper() == username.ToUpper())
                        { temp = authUser; }
                    }
                    temp.Logedin = true;
                    temp.LastActive = DateTime.Now;
                    temp.Save();

                }
            }


            [loggedinFilter] 
            [Layout("default"), Rescue("generalerror")]
            public abstract class BaseController : MonoRailHelper.HelperBaseController

            {
                function a bunch
            }
            }
        }

loggedinFilter is that is to fire and the temp.LastActive = DateTime.Now; does move up in the db as you go to "new" pages here but it's when you go back.. no change occures.

anyone have any ideas on how to fix this?

Thanks for the help.. Cheers -Jeremy

Était-ce utile?

La solution

You should not perform authentication in a filter attribute constructor.

Instead, follow the instructions for creating a filter: implement IFilter (your auth logic comes here), then apply the filter to the controller using the FilterAttribute. You can then (if you want) wrap the FilterAttribute in your own attribute implementation.

More info about filters.

Here's a Monorail auth filter that uses ActiveRecord, you could use it for reference.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top