Note that there are some explanatory texts on larger screens.

plurals
  1. POAssert Permissions in C#
    primarykey
    data
    text
    <p>I'm busy trying to understand the security stuff in c# and I'm struggling to see how Assert works. I'm using .net 3.5.</p> <p>I made a sample app to try figure this out.</p> <p>Calling method:</p> <pre><code>[FileIOPermission(SecurityAction.Deny, ViewAndModify = @"C:\")] static void Main(string[] args) { WriteTest testWriter = new WriteTest(); testWriter.Test(); Console.Read(); } </code></pre> <p>In a seperate class library I have:</p> <pre><code>public class WriteTest { public void Test() { try { FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Write, @"C:\"); permission.Assert(); using (StreamWriter sw = new StreamWriter(@"C:\test.txt")) { sw.WriteLine("testing!"); sw.Flush(); } Console.WriteLine("Writen to file!"); } catch (SecurityException sec) { Console.WriteLine("No privileges!"); } } } </code></pre> <p>This code executes fine and all. It will write to the file. My question is how exactly does this work? Does this not invalidate the security classes if I can just Assert the permissions I want so that it skips the checks? If I change Assert to Demand it throws an exception. </p> <p>Is the point of the security classes not to allow me to set permissions so that when I call a third party class I can prevent it from going rogue and doing stuff I don't want it to do? I know if I load the dll in an AppDomain I will get this effect even if the third party DLL does use Assert, it just seems strange that if I call it directly it will work. I've tried reading the MSDN documentation on Assert but I'm finding it hard to understand.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload