all groups > dotnet security > july 2005 >
You're in the

dotnet security

group:

Why use Demand()?


Re: Why use Demand()? ep
7/18/2005 10:32:26 AM
dotnet security:
it would, but you may have a situation where you want to demand permissions
before you do more work.
So if you have a lot more work to do, or perhaps you have multiple
permissions that you want to check before you do anything, check them first
and save yourself CPU time and cleanup if permission failed.




[quoted text, click to view]
SocketPermission(System.Net.NetworkAccess.Connect,System.Net.TransportType.T
cp,Server,Port);
[quoted text, click to view]

Why use Demand()? Bob
7/18/2005 10:43:05 AM
I am not sure why one should use the Demand() method? Wouldn't the attempt
to access the resource thrown the same security exception? For example does
the below Demand() actually help in any way?

SocketPermission socketPermission = new
SocketPermission(System.Net.NetworkAccess.Connect,System.Net.TransportType.Tcp,Server,Port);
socketPermission.Demand();

ipepServer = new IPEndPoint(IPAddress.Parse(Server),nPort);
Socket s = new Socket();
s. Connect(ipepServer);

Bob

AddThis Social Bookmark Button