加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 在调用action之前发生的ASP.NET MVC事件?

发布时间:2020-12-16 03:44:26 所属栏目:asp.Net 来源:网络整理
导读:我想根据一些路由数据设置Thread.CurrentCulture的值,但是在计算路由之后和调用action方法之前,我找不到挂起到该触发器的事件. 有任何想法吗? 解决方法 你可以写一个自定义 action filter attribute: public class CustomFilterAttribute : ActionFilterAt
我想根据一些路由数据设置Thread.CurrentCulture的值,但是在计算路由之后和调用action方法之前,我找不到挂起到该触发器的事件.

有任何想法吗?

解决方法

你可以写一个自定义 action filter attribute:

public class CustomFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        // This method is executed before calling the action
        // and here you have access to the route data:
        var foo = filterContext.RouteData.Values["foo"];
        // TODO: use the foo route value to perform some action

        base.OnActionExecuting(filterContext);
    }
}

然后,您可以使用此自定义属性修饰基本控制器.这里是一个blog post,说明了这种过滤器的示例实现.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读