在控制器动作访问行为过滤器的数据 [英] Accessing Action Filter's data in Controller Action

查看:83
本文介绍了在控制器动作访问行为过滤器的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[ApiBasicAuthorize]
public ActionResult SignIn()
{

}

我有这种所谓的ApiBasicAuthorize自定义过滤器。是否有可能访问控制器的动作里面ApiBasicAuthorize的数据(属性等)登入?

I have this custom filter called ApiBasicAuthorize. Is it possible to access ApiBasicAuthorize's data (properties etc) inside the controller action SignIn?

如果不是,我怎么从过滤器将数据传递给控制器​​动作?

If not, how do I pass data from the filter to controller action?

问候,
高塔姆耆那教

Regards, Gautam Jain

推荐答案

有是一个连接到HttpContext对象字典称为项目。使用这本字典的请求期间存储多个组件共享项目。

There is a dictionary called items attached to the HttpContext object. Use this dictionary to store items shared across components during a request.

public override void OnAuthorization(AuthorizationContext filterContext)
{
    filterContext.HttpContext.Items["key"] = "Save it for later";

    base.OnAuthorization(filterContext);
}

然后在你的code的任何地方在后面的请求......

Then anywhere in your code later in the request...

var value = HttpContext.Current.Items["key"];

这篇关于在控制器动作访问行为过滤器的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆