gpt4 book ai didi

c# - 控制对方法的访问

转载 作者:太空狗 更新时间:2023-10-29 20:31:16 27 4
gpt4 key购买 nike

有没有一种方法可以控制对 .net 中某些角色的方法的访问。喜欢

class A
{
//should only be called by Admins**
public void Method1() { }

//should only be called by Admins and PM's**
public void Method2() { }
}

我使用 Windows 身份验证只是为了检索用户名,仅此而已。用户角色在不同的应用程序中维护。我认为通过属性是可能的,但我不太确定如何

最佳答案

有可能,我已经在使用 asp.net 和 AzMan 作为身份验证的 Web 项目中使用它。

看看Code Access Security

根据内存,我们所有的方法看起来都像

[Permission(SecurityAction.Demand, "Permission")]
public void Method1

虽然已经有一段时间了,但实际上可能不是 100% 正确。

我还强烈建议您是否要将保护降低到这个级别以查看 task orientated permission approach因为这比基于角色的权限灵活得多

关于c# - 控制对方法的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12575676/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com