Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net mvc中的指定操作中更改全局授权筛选器属性_C#_Asp.net Mvc_Filter_Authorization_Action - Fatal编程技术网

C# 在asp.net mvc中的指定操作中更改全局授权筛选器属性

C# 在asp.net mvc中的指定操作中更改全局授权筛选器属性,c#,asp.net-mvc,filter,authorization,action,C#,Asp.net Mvc,Filter,Authorization,Action,我的所有操作都已在配置中注册为全局授权筛选器。但我希望某些指定的操作不使用全局授权筛选器或需要更改某些筛选器属性 例如: the global filter:[new AA(){NeedLogin=ture}] [new AA(){NeedLogin=false}] public ActionResult LogOn() { // go to log on page //............ } Filter like this: public bool NeedLogin{g

我的所有操作都已在配置中注册为全局授权筛选器。但我希望某些指定的操作不使用全局授权筛选器或需要更改某些筛选器属性

例如:

the global filter:[new AA(){NeedLogin=ture}]

[new AA(){NeedLogin=false}]
public ActionResult LogOn()
{
  // go to log on page
  //............
}

Filter like this:

public bool NeedLogin{get;set;}
protected override bool AuthorizeCore(HttpContextBase httpContext) 
{
       //if this Action is not need login ,the return true directly. also don't check     usename        and password
if(!this.NeedLogin){
    return true;
}

//Check authorize  return true or false

}
注意:我认为“LogOn”操作有两个相同的过滤器,一个是“true”,另一个是“false”。但是我希望“LogOn”的“NeedLogin”只是“false”


哦,天哪,这个编辑器太难了。

显示自定义授权过滤器的代码public bool NeedLogin{get;set;}protected override bool AuthorizeCore(HttpContextBase httpContext){//如果这个操作不需要登录,则直接返回true。如果(!this.NeedLogin){返回true;},也不要检查usename和password//检查authorize return true或false}我为您更新我的帖子,谢谢。您是否尝试过
[AA(NeedLogin=false)]
?也许我的想法是错误的。该操作应该添加两个“AA”过滤器。事实上,我需要将“NeedLogin”属性更改为“false”。之后,我添加了一行代码:“[AttributeUsage”(AttributeTargets.Method,AllowMultiple=false,Inherited=true)]到costom筛选器,因此当我在filter core方法中调试时,“IsNeedLogin”是“false”。可能关于筛选器的顺序?