![]() |
|
|
|||||||
![]() |
MCTS - Help on PrincipalPermission Demand Throwing Exception |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
[PrincipalPermission(SecurityAction.Demand, Name=@"MYDomain\MyUserName")]
static void TestMethod() { Console.WriteLine("Test Message"); } public static void Main(string[] args) { WindowsIdentity wID = WindowsIdentity.GetCurrent(); Console.WriteLine("Current User: {0}", wID .Name); try { TestMethod(); } catch (System.Security.SecurityException ex) { Console.WriteLine("Exception: {0}", ex.Message); } Console.Read(); } Abba Biya |
|
|
|
|
#2 |
|
Posts: n/a
|
Shoud add the following line for it to work.
AppDomain.CurrentDomain.SetPrincipalPolicy(Princip alPolicy.WindowsPrincipal); some observations: Security Principals listed on separate demands will be OR whereas if listed all in one SecurityAction.Demand, it will be AND. [PrincipalPermission(SecurityActioin.Demand, Authenticated = true, Role = @"CONTOSO\Admins")] will allow only authenticated and users from Admins group. If we change it to the following: [PrincipalPermission(SecurityActioin.Demand, Authenticated = true)] [PrincipalPermission(SecurityAction.Demand, Role = @"CONTOSO\Admins")] Authenticated users with out being Admins will be able to run this code. this is a Logical OR. This is great. "Abba Biya" wrote: > [PrincipalPermission(SecurityAction.Demand, Name=@"MYDomain\MyUserName")] > static void TestMethod() > { > Console.WriteLine("Test Message"); > } > > public static void Main(string[] args) > { > WindowsIdentity wID = WindowsIdentity.GetCurrent(); > Console.WriteLine("Current User: {0}", wID .Name); > > try > { > TestMethod(); > } > catch (System.Security.SecurityException ex) > { > Console.WriteLine("Exception: {0}", ex.Message); > } > > Console.Read(); > } > Abba Biya |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| exception has been thrown by the target of an invocation | mintcremes | General Help Related Topics | 0 | 07-03-2008 02:51 AM |
| java.net.SocketException: Broken pipe exception at HttpServletRequest | sadasivar | Software | 0 | 03-11-2008 04:40 AM |
| exception unknown software exception error - Excel.exe | mfinamore | Software | 0 | 11-15-2007 04:54 PM |
| Exception in thread "main" java.lang.NoClassDefFoundError: | prakash.nmsp@gmail.com | Software | 0 | 06-29-2007 10:03 AM |
| how to overcome the nullpointer exception | arputharaj | Software | 0 | 11-11-2006 07:05 AM |