Need to know if user is a windows administrator

Need to know if user is a windows administrator

Old forum URL: forums.lhotka.net/forums/t/3810.aspx


Ton Smeets posted on Tuesday, October 30, 2007

Hi,

To perform some tasks (like creating a new database) my application needs to know if the user is a windows administrator. How do I get this value into my application.

I know this is total Off-Topic, my apologies for that. It keeps your mind sharp.

Thanks

ajj3085 replied on Tuesday, October 30, 2007

You'll need to cast the ApplicationContext.User to a WindowsPrincpal (I assume you're using windows auth).  Then you can call the IsInRole overload that takes a role enum for the common roles.

Ton Smeets replied on Tuesday, October 30, 2007

nope, I'm using the CSLA pricipal all over my application. I only need to grab some information from the operating system, wether the user is an Administrator.

thanks

ajj3085 replied on Tuesday, October 30, 2007

Ok, well the same suggestion applies, you'll just create a WindowsPrincipal object using the WindowsIdentity returned by WindowsIdentity.GetCurrent, assuming you want the currently logged on user.

Ton Smeets replied on Tuesday, October 30, 2007

So, just create a windowsprincipal object. Get the info I need and let it get out of scope. Does this effect my cslaprincipal living on my thread, or does it only interfere when I set it to be the applicationcontext.user? I guess only creating the object to look up information does not effect the dataportal.

But knowing for sure is better.

Thanks

ajj3085 replied on Tuesday, October 30, 2007

It will have no effect on your ApplicationContext.User (which is just short for Thread.CurrentThread.CurrentPrincipal) unless you change it yourself.   So yes, just create, use it, and let it go... you may need to Dispose it, I can't recall.

Copyright (c) Marimer LLC