Common way to change users at runtime and their permissions in WPF/Prism desktop application

StackOverflow https://stackoverflow.com/questions/12891670

  •  07-07-2021
  •  | 
  •  

Question

I have troubles with WPF desktop application based on Microsoft Prism Framework. The application has Logon dialog on startup that creates AuthenticationContext (User and Role) and runs Prism Bootstrapper (which creates ShellWindow and load Modules). Permissions are implemented using Markup Extensions and therefore parsed on view creation as I understand:

<MenuItem IsEnabled="{op:AuthToEnabled {x:Static a:ACL.CAN_CLOSE}}" ...>

Now I'm trying to add the abillity to change current user (and his permissions) at runtime. The possible ways of recreating entire bootstrapper or shell window does't work as expected and in generally look like hacks.

Is there a common way or best practice to do such things (users, permissions itself and their changes) when using Prism or WPF in general?

Was it helpful?

Solution

I'm not positive, but I believe {x:Static } is only evaluated once and won't get re-evaluated even if your permissions change

What about just restarting your application entirely when the user chooses to change logins?

I do this with one of my applications which requires a restart when the login info changes:

Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top