Re: how to protect a class with a principalpermissionattribute?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



PrincipalPermissionAttribute class is used to control access to
methods, not classes, so move the attribute statement to just before
the method you want to control. You also need a
system.appdomain.currentdomain.setprincipalpolicy statement in the
constructor for the form. Then, put the call to the method in a try/
catch block to trap any exception that the runtime might throwif
there are not adequate permissions to execute the method.


On Mar 26, 8:45 am, "xamman" <xamma...@xxxxxxxxx> wrote:
hello! anyone ever manage to do this? after trying nearly everything
i
can think of my code (below) still gives 'request for principal
permissions failed' .

many thanks
x
.
.
.
.
.

Protecting to class - this doesnt work (& the tried
role:="administrators", name:="administrator" etc)
< PrincipalPermissionAttribute(SecurityAction.Demand, Role:="BUILTIN
\Administrators") _
Public Class Form1 Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal and As
System.EventArgs) Handles MyBase.Load
Messagebox("form should load if user is admin")
End Sub

if you need more details about this problem:http://groups.google.com/group/microsoft.public.dotnet.languages.vb/b...


.