在覆盖方法中使用不同的主载体

发布于 2025-01-25 19:13:05 字数 743 浏览 1 评论 0原文

我的基类中有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月隐月明月朦胧 2025-02-01 19:13:05

我认为问题在于您在derivedClass中使用BASECLASS,因此deleteall方法导致derivedclass需要既有“操作员”和“ deleter”角色。

您可以尝试使用或。
有关详细信息,请参见下面的链接。
principalpermission on Method on Method如果应用于类别

基础并得出班级

I think the problem is that you are using the baseclass in the derivedclass, so the DeleteAll method resulting in DerivedClass 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文