A
Andrus
I have .NET 2 WinForms MDI application containing 250 ToolStripMenu items.
I need to make some submenus invisible and individual menus invisible if
user has no rights or insuficient level of access. This can be determined at
menu creation time.
Possibilites:
1. Modify WinForms designer generated code manually by not creating
unwanted items. After that it is no more possible to use designer anymore
so this is difficult.
2. Use form OnLoad to remove unwanted items:
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
if (!SecurityManager.IsAllowed("Invoice") &&
!SecurityManager.IsAllowed("Order")) {
FileMenuStrip.DropDownItems.RemoveByKey("UnWantedMenu");
}
This requires writing a lot of code and hardcoding all menu item names
3. Store access levels in Tag property in designer:
Tag = @"!SecurityManager.IsAllowed(""Invoice"") &&
!SecurityManager.IsAllowed(""Order"")";
In OnLoad event use reflection to evaluate Tag expression and use
RemoveByKey to remove unwanted items.
In this case security information if placed in every object property, no
central place to control.
4. Create menus dynamically from some class attributes or from some other
metadata.
Where to find more information and sample code ?
Which is best way for this ?
Andrus.
I need to make some submenus invisible and individual menus invisible if
user has no rights or insuficient level of access. This can be determined at
menu creation time.
Possibilites:
1. Modify WinForms designer generated code manually by not creating
unwanted items. After that it is no more possible to use designer anymore
so this is difficult.
2. Use form OnLoad to remove unwanted items:
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
if (!SecurityManager.IsAllowed("Invoice") &&
!SecurityManager.IsAllowed("Order")) {
FileMenuStrip.DropDownItems.RemoveByKey("UnWantedMenu");
}
This requires writing a lot of code and hardcoding all menu item names
3. Store access levels in Tag property in designer:
Tag = @"!SecurityManager.IsAllowed(""Invoice"") &&
!SecurityManager.IsAllowed(""Order"")";
In OnLoad event use reflection to evaluate Tag expression and use
RemoveByKey to remove unwanted items.
In this case security information if placed in every object property, no
central place to control.
4. Create menus dynamically from some class attributes or from some other
metadata.
Where to find more information and sample code ?
Which is best way for this ?
Andrus.