C# 特性类的属性第二次请求会被保存,理论依据是什么?急!
问题描述:
示例如下:
特性类:
C# code
public class T3Controller : Controller
{
// GET: Sys/T3
[TestMyA]
public ActionResult n0()
{
string s = "ActionName 应是:默认空 , id: 默认-1";
MyString.DoRn(s);
return Content("n0");
}
}
控制器:
C# code
public class TestMyA : ActionFilterAttribute
{
public int NoPowerShowType = -1;//无权时如何展示,1为主页,2为json,3为弹窗
public string ActionName { set; get; }//可自定义的ActionName
#region 0. 权限过滤
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
NoPowerShowType++;
if (ActionName.IsNullOrEmpty())
{
ActionName = "new";
}
}
#endregion
}
查看监视如下属性时:
public int NoPowerShowType = -1;//无权时如何展示,1为主页,2为json,3为弹窗
public string ActionName { set; get; }//可自定义的ActionName
第二次请求,保存了上次的值。
而且不同行为间也会串用,原因是什么,有高手吗?急!
答
终于解决了,特性属性不能变动。否则会被action缓存,每个action各自独立。所以要另设置自定义变量。
答
如何,让属性像正常变量一样,生命周期在整个请求内?