how to protect a class with a principalpermissionattribute?

X

xamman

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/micr...a75256b91e7/001879dbbf09528d#001879dbbf09528d
 
B

billsahiker

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.
 
X

xamman

thanks but msdn says you can protect a class (but i havent got the
example to work for me) and gives this example
<PrincipalPermissionAttribute(SecurityAction.Demand, _
Name := "Bob", Role := "Supervisor")> Public Class SampleClass



my question is when protecting a class, where do you put the call to
system.appdomain.currentdomain.setprincipalpolicy ?

is there an attribute that does this for assemblyinfo.vb?

thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top