By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,978 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,978 IT Pros & Developers. It's quick & easy.

protecting a class declarativly (going mad)

P: n/a
hi there! according to msdn (link at bottom) i should be able to
protect a whole class declaratively as above. However i keep getting
'request for principal permissions failed' exceptions.

in the msdn article a reference is made to include
AppDomain.CurrentDomain.SetPrincipalPolicy(Princip alPolicy.WindowsPrincipal)
in your code to set the appdomain principal.I can understand how to
use setprincipalpolicy to protect a method declaratively (working code
example at bottom)

but how do i protect a CLASS?

the question is where & how to SetPrincipalPolicy Declaratively? is
there an attribute in assemblyinfo.vb for this?

many thanks,
X

a)msdn link:
http://msdn2.microsoft.com/en-us/lib...attribute.aspx

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

AppDomain.CurrentDomain.SetPrincipalPolicy(Princip alPolicy.WindowsPrincipal)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
dowork()
End Sub
<PrincipalPermissionAttribute(SecurityAction.Deman d, Role:="BUILTIN
\Administrators")Sub dowork()
MessageBox.Show("protected")
End Sub
end class

Mar 24 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.