Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5844077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:14:35+00:00 2026-05-22T12:14:35+00:00

I have a Winforms project that is loosely based on MVVM. Security is implemented

  • 0

I have a Winforms project that is loosely based on MVVM. Security is implemented by the domain layer by using the PrincipalPermissionAttribute, like so:

Public Class Order

     <PrincipalPermissionAttribute(SecurityAction.Demand, Role:="Managers")> _
    Public Sub ChangeBillingAddress(NewAddress as Address)

        Me.BillingAddress = NewAddress

    End Sub


End Class

I would like for my ViewModel to be able to instruct the view on which controls to enable/disable based on the PrincipalPermissionAttribute in the domain:

Public Class OrderViewModel

    Private _Order as Order
    Public Sub New(Order as Order)
        _Order = Order
    End Sub

    Public Readonly Property ChangeBillingAddressEnabled as Boolean
        Get
            'Here I want to take Thread.CurrentPrincipal and evaluate
            'it's Role against the PrincipalPermissionAttribute on 
            '_Order.ChangeBillingAddress.  If the user will succeed
            'in changing the billing address return True, else return False.
        End Get

    End Property
End Class

Is there a way for the ViewModel to evaluate the PrincipalPermissionAttribute and determine if the current Thread.Principal will succeed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:14:36+00:00Added an answer on May 22, 2026 at 12:14 pm

    Yes, you most definitely can get back the attributes on the method and do stuff with them.

    For example (sorry in C#):

    return _Order.GetType()
                 .GetMethod("ChangeBillingAddress")
                 .GetCustomAttributes(typeof(PrincipalPermissionAttribute), true)
                 .Cast<PrincipalPermissionAttribute>()
                 .All(r => IsPermittedAccess(r, Thread.CurrentPrincipal));
    

    Where you can work out what to do with the attribute:

    bool IsPermittedAccess(PrincipalPermissionAttribute rule, IPrincipal user)
    {
        // return ?
        throw new NotImplementedException();
    }
    

    I’ll leave the last task of deciding whether the user meets the attribute’s requirements or not. I’m not familiar enough with that part of the framework. Also you can deal with the error handling (e.g. method doesn’t exist with that name).

    I’ll also add that you would probably want to cache (in a static field perhaps?) the results of the reflection on the method since it’ll never change. You’ll also want to be sure that your view model is firing property change notifications when the principal changes or principal’s roles collection changes (that is, if it does in deed change).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an old project that is designed using VS2005 and WinForms. Everything works
I'm writing a VB.NET Winforms project based on MVVM (using Winforms binding). My instinct
I have a VERY simple C# Winforms project that I made using Visual Studio
I have a .NET 3.5 WinForms project that uses several 3rd party controls and
I have a Winforms project with a bunch of User controls. I'd like the
I have a project that i started as a WinForms application as that was
I have an existing C# 3.0 WinForms project with .NET 3.5 that talks to
I am currently working on a project that hosts WinForms designer. I am using
I have a vb.net 2.0 winforms project that is full of all kinds of
I have a winforms project that I want to develop a custom control for.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.