Using Prism 6
The validation whenever user is granted to view certain view is done with ThreadPrincipal. This method works when view is created in the viewModel:
try{
View someView = new View ();
mainRegion.Add(someView , "viewName");
mainRegion.Activate(someView );
}
catch (SecurityException)
{
}
And view has:
[PrincipalPermission(SecurityAction.Demand, Role = "Administrators")]
However creating a view in a viewModel is not a good practice so if RequestNavigate to navigate between views is used:
_regionManager.RequestNavigate(RegionNames.ContentRegion, new Uri(viewName, UriKind.Relative));
And same try, catch wrapper is wrapped around:
try{
_regionManager.RequestNavigate(RegionNames.ContentRegion, new Uri(viewName, UriKind.Relative));
}
catch (SecurityException)
{
}
The exception is not caught.
Question: How to catch the exception?
First, don't create Views in the ViewModel. This is a big MVVM "No-no". When using RequestNavigate, there is a callback that you can use with information about the navigation action. It will tell you is the navigation operation failed and what the error message was when it failed.
See this sample: https://github.com/PrismLibrary/Prism-Samples-Wpf/tree/master/18-NavigationCallback