根据这里的问题,ASP.NET MVC Pass object from Custom Action Filter to Action
(用于MVC)是否存在类似的对象,我们可以从
内部向其中添加项目或值public override void OnActionExecuting(HttpActionContext actionContext)
{
}
(用于WebAPI),并在几秒钟后通过Controller的action方法本身对其进行访问?
答案 0 :(得分:0)
这有效:
设置数据:
public class MyAwesomeFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
//add stuff here.. to be accessed later
actionContext.Request.Properties.Add("myKey69", myValue);
}
}
检索数据:
[MyAwesomeFilter]
public IHttpActionResult MyController( [FromBody] string myParmStr ) {
//retrieve the obj you inserted in filter...
obj myValue = null;
if (Request.Properties.TryGetValue("myKey69", out myValue)) {
//logic here...
}
}