我在 MVC 中使用 Abp 框架。我有一個匿名方法,它在其中呼叫一堆方法,所有方法都具有[Authorize]屬性。我想將此父方法和所有內部方法呼叫為匿名,而不將所有內部方法設定為匿名。目前我收到一個關于未被授權呼叫這些子方法的錯誤。我怎樣才能做到這一點?謝謝
例如:
[Authorize]
void A(){}
[Authorize]
void B(){}
[AbpAllowAnonymous]
void C(){
//call these two
A();
B();
}
uj5u.com熱心網友回復:
您可以將這些方法分發到共享的私有方法中。使用此模式,您可以保持授權要求不變,但共享功能。示例替代模式:
[Authorize]
void A(){ _a(); }
[Authorize]
void B(){ _b(); }
[AbpAllowAnonymous]
void C(){
//call these two
_a();
_b();
}
// shared private methods
private void _a() {}
private void _b() {}
uj5u.com熱心網友回復:
也許你可以OverrideAuthorizationAttribute在你的動作上使用。
表示覆寫在更高級別定義的授權過濾器的過濾器屬性。( https://docs.microsoft.com/en-us/previous-versions/aspnet/dn308862(v=vs.118)
[Authorize]
void A(){}
[Authorize]
void B(){}
[OverrideAuthorization]
[AllowAnonymous]
void C(){
//call these two
A();
B();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/386295.html
下一篇:傳遞到字典中的模型項的型別為..但此字典需要System.Collections.Generic.IEnumerable'型別的模型項
