在覆盖方法中使用不同的主载体
我的基类中有一个deleteall
方法,该方法需要调用特定角色(“删除剂”)。我有一个源自基类的第二类。在派生的类中,我想覆盖deleteall
方法,以便我可以要求该方法一个不同的角色(“运算符”)。
public BaseClass
{
[PrincipalPermission(SecurityAction.Demand, Authenticated = true, Role = "Remover")]
public virtual void DeleteAll(IEnumerable<Guid> ids)
{
//Code to delete each id
}
}
public DerivedClass : BaseClass
{
[PrincipalPermission(SecurityAction.Demand, Authenticated = true, Role = "Operator")]
public virtual void DeleteAll(IEnumerable<Guid> ids)
{
base.DeleteAll(ids);
}
}
如果我调用derivedClass
's deleteall
方法,它将要求用户具有“操作员”和“删除剂”角色。我只希望需要“操作员”角色。
在覆盖方法时,有没有办法覆盖委托人?
I have a DeleteAll
method in my base class that requires a specific role ("Remover") to be called. I have a second class that derives from the base class. In the derived class, I want to override the DeleteAll
method so I can require a different role ("Operator") to the method.
public BaseClass
{
[PrincipalPermission(SecurityAction.Demand, Authenticated = true, Role = "Remover")]
public virtual void DeleteAll(IEnumerable<Guid> ids)
{
//Code to delete each id
}
}
public DerivedClass : BaseClass
{
[PrincipalPermission(SecurityAction.Demand, Authenticated = true, Role = "Operator")]
public virtual void DeleteAll(IEnumerable<Guid> ids)
{
base.DeleteAll(ids);
}
}
If I call DerivedClass
's DeleteAll
method, it will require a user to have both the "Operator" and the "Remover" roles. I only want the "Operator" role to be required.
Is there a way to override PrincipalPermission when overriding a method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于您在
derivedClass
中使用BASECLASS
,因此deleteall
方法导致derivedclass
需要既有“操作员”和“ deleter”角色。您可以尝试使用或。
有关详细信息,请参见下面的链接。
principalpermission on Method on Method如果应用于类别
基础并得出班级
I think the problem is that you are using the
baseclass
in thederivedclass
, so theDeleteAll
method resulting inDerivedClass
needs to have both "operator" and "deleter" roles.You can try combining multiple PrincipalPermissionAttribute requirements using OR.
See the link below for details.
PrincipalPermission on Method doesn't work if applied to Class
How to apply OR in PrincipalPermission in base and derive class