RE: Custom permission
From: Eugene V. Bobukh [MS] (eugenebo_at_online.microsoft.com)
Date: 09/12/03
- Next message: Michel Gallant: "Re: Encrypting symmetric keys"
- Previous message: Marcelo Palladino: "Custom permission"
- In reply to: Marcelo Palladino: "Custom permission"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Fri, 12 Sep 2003 21:25:30 GMT
Marcelo,
It works as little bit differently. The idea of Deny() is not to rais an
exception directly, but to make it rasing if someone in the deeper frame
does Demand() for the same permission.
So, assuming that your CustomPermission is implemented acordind to the
spec, the following pieces of code wil exhibit these types of behavior:
1)
void Bar()
{
(new CustomPermission(PermissionState.Unrestricted)).Demand(); // <-
here you get the exception
}
void Foo()
{
(new CustomPermission(PermissionState.Unrestricted)).Deny();
Bar();
}
public static void Main()
{
Foo();
}
2) Note, please, that without Deny there still may be an expection expected
simply in the case if your assembly is not granted you CustomPermission:
void Bar()
{
(new CustomPermission(PermissionState.Unrestricted)).Demand(); // <- If
permission is not granted, expection will be raised, too.
}
public static void Main()
{
Bar();
}
Thanks,
Eugene V. Bobukh
/*
This message is provided "as is" and does not constitite any
responsibilities or opinions conformace
*/
--------------------
| From: "Marcelo Palladino" <marcelopalladino@uol.com.br>
| Subject: Custom permission
| Date: Fri, 12 Sep 2003 14:34:24 -0300
| Lines: 31
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#BTmAPVeDHA.2748@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.security
| NNTP-Posting-Host: 200-204-145-221.picture.com.br 200.204.145.221
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.security:2836
| X-Tomcat-NG: microsoft.public.dotnet.security
|
| Hi!
|
| I am trying to understand as creating personalized permissions. In
MSDN
| there is a paper that describes as creating one.
|
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
| ml/cpconimplementingcustompermission.asp)
|
| Good, the creation went to copy only from paper (I created an alone
| assembly for permissions and I copied it for GAC). When I will use (code
| below), no exception is being generated.
|
| public string GetNome()
| {
| new CustomPermission(PermissionState.Unrestricted).Deny();
| return "Palladino";
| }
|
| private void button1_Click(object sender, System.EventArgs e)
| {
| //Here it should not generate an exception?
| Text = this.GetNome();
| }
|
|
| Thank´s in advance
|
|
|
| Marcelo Palladino
|
|
|
- Next message: Michel Gallant: "Re: Encrypting symmetric keys"
- Previous message: Marcelo Palladino: "Custom permission"
- In reply to: Marcelo Palladino: "Custom permission"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]