授权属性
我有一个来自客户端的 WPF 应用程序,我需要为类中的某些方法添加 IsInRoleAtrribute。
所以我像这样创建了 IsInRole 类,作为测试;
namespace CustomAttributeSample
{
[System.AttributeUsage(System.AttributeTargets.Method)]
public class IsInRoleAttribute : Attribute
{
public string Role { get; set; }
public IsInRoleAttribute()
{
//open the xml file
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("Data.xml");
}
public override bool Match(object obj)
{
return false;
}
public override bool Equals (object obj)
{
return false;
}
}
}
我这样装饰我的方法,再次作为迄今为止的测试;
[IsInRole(Role="Admin")]
private bool Save()
{
但是我无法阻止该方法的执行。
我可以在 MVC 中做到这一点,没有问题,但这是我多年来的第一个 WPF 应用程序,所以我知道我在这里遗漏了一些东西。
I have a WPF application from a client that I need to add a IsInRoleAtrribute to for certain methods in a class.
So I created my IsInRole class like this, as a test;
namespace CustomAttributeSample
{
[System.AttributeUsage(System.AttributeTargets.Method)]
public class IsInRoleAttribute : Attribute
{
public string Role { get; set; }
public IsInRoleAttribute()
{
//open the xml file
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("Data.xml");
}
public override bool Match(object obj)
{
return false;
}
public override bool Equals (object obj)
{
return false;
}
}
}
And I decorate my method like this, again as a test so far;
[IsInRole(Role="Admin")]
private bool Save()
{
However I cannot prevent the method from being executed.
I can do this in MVC no probs but this is my first WPF application in a number of years so I know I'm missing something here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对此也不是很熟悉,但尝试用它代替:
如果您使用 MVVM 范例,这应该可以工作;-)
来源:WPF 命令和基于声明/角色的安全性
not very familiar with that either but try to put this instead:
this should work if you are using the MVVM paradigm ;-)
source: WPF Command and claim/role based security