Controlling Read/Write Permissions Per User

  • Thread starter Thread starter Jeremy S.
  • Start date Start date
J

Jeremy S.

I'm writing a Windows Forms app (connecting to SQL Server db) that will need
to enable/disable access to various UI controls based on the particular user
that is currently logged in.

My question:
What are some of the building blocks that I should look to use? E.g., how do
I know who the current user is? Should I create some custom class that has a
"CurrentUserID" property and then at runtime in Form_Load set the UI control
properties based on the value of the property? Is there some less "home
grown" way I should be looking to accomplish this - perhaps some features
built into the Framework?

Thanks!
 
You will need to use the System.Security.Principal namespace. To get the
WindowsPrincipal instance for the current user, you call:

WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());

The WindowsPrincipal class has a member of type IIdentity, called Identity.
This provides all the information you need to know about the current user.
See
http://msdn2.microsoft.com/en-us/library/system.security.principal.iidentity.aspx
for details.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

If the truth hurts, wear it.
 
Back
Top