在 .net2.0 单轨 setop 中使用自定义过滤器 BeforeAction 并不总是触发

发布于 2024-12-08 21:10:27 字数 1547 浏览 2 评论 0原文

我制作了一个自定义过滤器,它将在每个操作(请求)上触发。所以问题似乎是,当用户刷新时第一次运行该操作时,它不会再次运行。就像它被缓存了什么的。我确实第一次触发了过滤器,因此代码正在工作(-ish),但页面的第二次加载却让我丧命。这基本上是代码。

        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
            }
            }
        }

LoginFilter 是要触发的并且 temp.LastActive = DateTime.Now;当您转到此处的“新”页面时,确实会在数据库中向上移动,但当您返回时..不会发生任何变化。

有人对如何解决这个问题有任何想法吗?

谢谢你的帮助..干杯-杰里米

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薆情海 2024-12-15 21:10:27

您不应在过滤器属性构造函数中执行身份验证。

相反,请遵循创建过滤器的说明:实施 IFilter(您的授权逻辑在这里),然后使用 FilterAttribute 将过滤器应用到控制器。然后您可以(如果您愿意)将 FilterAttribute 包装在您自己的属性实现中。

有关过滤器的更多信息

这是一个使用 Monorail 身份验证过滤器ActiveRecord,你可以参考一下。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文