Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to handle Security Exception

$
0
0

Hi

I am using some mechanism to manage the UserControl/views  from WPF main window:

class Switcher
    {
        public static MainWindow pageSwitcher;
        public static void Switch(UserControl newPage)
        {
            pageSwitcher.Navigate(newPage);
        }
    }

public partial class MainWindow
    {
       public MainWindow()
       {
            InitializeComponent();
            Switcher.pageSwitcher = this;
            Switcher.Switch(new Login());
       }

       public void Navigate(UserControl nextPage)
       {
            this.contentControl.Content = nextPage;
       }
    }

Now whenever I want to switch the View I use below code:

Switcher.Switch(new Home());

But now issue is my Home UserControl class is something like this:

[PrincipalPermission(SecurityAction.Demand, Role = "User")]
public partial class Home : UserControl
{  }
 

As explained HERE implementing custom authentication and authorization.

Now whenever I am trying to switch the view I have to create new instance of User Control Class like "newHome()" but if user don’t have permissions on the Home page then I get security exception.

My question is that, is there any way where I can handle this Security Exception in Switcher class? If so then will be able to create separate error page which will get displayed if user doesn't have permissions.

Please suggest.

Thanks in advance.




Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>