【发布时间】:2012-08-24 08:05:56
【问题描述】:
我只是不想为每个属性使用“经理”,而是为此使用一些枚举。
但似乎不可能还是我错了?
所以我尝试替换
[RequiresRole("Managers")]
与
[RequiresRole(HardCodedRoles.Managers.ToString())]
...
public enum HardCodedRoles
{
Administrators,
Managers
}
【问题讨论】:
-
您能否添加更多细节,以便我们知道您要完成的工作是什么?
-
我只是不想使用字符串“AnyRoleName”,我想从枚举中放置一些项目而不是它。但是VS报错An attribute argument must be an constant expression, typeof expression or array creation expression of an attribute parameter type
-
如果 HardcodedRoles.Managers 是一个 const 字符串,这将起作用。另一方面,如果 HardcodedRoles 是一个枚举,则必须继承 AuthorizeAttribute 并实现自己的,将 HardcodedRoles 和/或 HardcodedRoles[] 传递给构造函数。
-
@Maciej 你能提供任何样品吗?我刚刚找到了一些链接stackoverflow.com/questions/2397923/…,这里是stackoverflow.com/questions/1315524/…,这里是geekswithblogs.net/thomasthedeuce/archive/2009/06/25/…,但无法弄清楚它是如何完成的。
标签: c# .net wcf-ria-services