Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>Assert()</code> is useful when <em>less</em>-privileged code ("Assembly A") calls <em>more</em>-privileged code ("Assembly B") to perform some task. To carry out that task, Assembly B needs to run code that requires a powerful permission—a permission that Assembly A might not have. So Assembly B first demands a less-powerful permission (the permission to perform the task in the first place) and then asserts the more-powerful permission to actually carry out the task.</p> <p>For example, suppose a partial-trust Silverlight app wants to make an HTTP request using the <code>System.Net.WebRequest</code> class. Establishing a network connection requires <code>SocketPermission</code>, but this is a powerful, low-level permission that shouldn't be granted to untrusted code from the Internet. So <code>WebRequest</code> demands a less-powerful permission, <code>WebPermission</code>, and then asserts <code>SocketPermission</code> before going on to establish the network connection.</p> <p>Now, in your particular example, the <code>Assert()</code> overrides the <code>Deny</code> because the class library is running <em>at the same privilege level</em> as the application—both the application and class library are likely running as Full Trust. An assembly can always <code>Assert()</code> any permission in its grant set. To enforce the <code>Deny</code> on the class library, you would have to put the class library in a sandbox.</p> <p><strong>Note:</strong> In .NET 4.0, <code>Deny</code> has been deprecated. From <a href="http://msdn.microsoft.com/en-us/library/dd233103.aspx#obsolete" rel="nofollow">MSDN Library</a>:</p> <blockquote> <p>Runtime support has been removed for enforcing the Deny, RequestMinimum, RequestOptional, and RequestRefuse permission requests. In general, these requests were not well understood and presented the potential for security vulnerabilities when they were not used properly:</p> <ul> <li>A Deny action could be easily overridden by an Assert action. The code in an assembly was able to execute an Assert action for a permission if the permission was in the grant set for the assembly. The Assert prevented the Deny from being seen on the stack, making it ineffective.</li> </ul> </blockquote>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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