在自定义筛选器属性更改ActionExecutingContext值 [英] Changing ActionExecutingContext values in Custom Filter Attribute
问题描述
我有我想要使用某些ActionResults来看看正在尝试的数据和设置,其中一些规则被违反值自定义过滤器的属性。
I have a custom filter attribute that I want to use on certain ActionResults to look at the data being attempted and to set values where certain rules are violated.
所以;
public class SpecialActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
foreach (string value in filterContext.Controller.ValueProvider.Keys)
{
string h = filterContext.Controller.ValueProvider[value].AttemptedValue;
if (h == "1")
{
//set the value of the key to be say "one".
}
}
base.OnActionExecuting(filterContext);
}
}
这可能吗?
推荐答案
您可以检查或修改将要传递给操作的参数 - 看到 ActionExecutingContext.ActionParameters 此属性。这是一个非常通用的解决方案,虽然。如果你能提供你想要做的事情多一点的背景下,我们也许能够提供更多的相关建议。
You can inspect or modify the parameters that will be passed to the action - see the ActionExecutingContext.ActionParameters property for this. This is a very general solution, though. If you could provide a little more context on what exactly you're trying to do, we might be able to provide more relevant suggestions.
这篇关于在自定义筛选器属性更改ActionExecutingContext值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!