When do we use Demand and when do we use Assert?

Feb 2 2004 2:15 PM
Hi, I am a newbie in .net security so please bear with me. Normally when I access a resource let say a file, I instantiate a Permission e.g. FileIOPermission FIO = new FileIOPermission(FileIOPermissionAccess.Append | FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, @"C:\TEMP\whatever.txt"); // I do this normally try{ FIO.Demand(); FIO.Assert() // ... write to the file etc. } catch(Exception e) { //... do some exception logging } finally { CodeAccessPermission.RevertAssert(); } My question is this: if I removed the Demand() statement will it affect the way I access the file? I've read that the Demand method walks thru the stack so it may affect my applications overall performance but I haven't noticed any differences when I commented it out. Maybe I am mixing up the two that's why I'm confused. Any help or clarification would be highly appreciated. Hanggang sa muli, Tikbalang.

Answers (1)