Authorisation Attribute
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;
[IsIn开发者_JAVA技巧Role(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.
not very familiar with that either but try to put this instead:
[AuthorizationAttribute(AuthorizationType.Allow, "Admin")]
this should work if you are using the MVVM paradigm ;-)
source: WPF Command and claim/role based security
精彩评论