Catch exception in wpf PrincipalPermission(SecurityAction.Demand, Role = "Admin")

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danielxu
    New Member
    • Aug 2013
    • 1

    Catch exception in wpf PrincipalPermission(SecurityAction.Demand, Role = "Admin")

    I am working on a wpf app on basic authentication set ups with different roles. Say, two rules like Admin and Staff. Admin can add/delete users, but Staff can't. Now If I login as Admin, I can add/delete users who can access the app, but if I login as the role Staff, if I do add/delete users operations, the application will crash. I know the problem is I only allow Admin to perform such actions. But any ideas on how to throw an exception so that the app won't crash. I post my code, any ideas? Thanks in advance.

    Code:
    [PrincipalPermission(SecurityAction.Demand, Role = "Admin")]
    public partial class UserRegistrationView : Window, IView
    {
        public UserRegistrationView()
        {
    
            InitializeComponent();
        }
    
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    
        public IViewModel ViewModel
        {
            get
            {
                return DataContext as IViewModel;
            }
            set
            {
                DataContext = value;
            }
        }
    }
Working...