RE: making permissions optional

Hi Dave,

The Permission Calculator Tool calculates the minimum permission set
required to run an application by examining all applicable code paths of
all application assemblies and dependency assemblies:

#Permission Calculator Tool (Permcalc.exe)
Starting from the entry point of the application, the tool traces all code
paths through all application assemblies and the shared and system
libraries called from the application. The tool maintains a simulated call
stack that contains all the assemblies involved in the code path trace. On
every code path trace, the tool checks for the presence of declarative
demands, link demands, and declarative stack walk modifiers.

If you use Reflector to view J# Assembly.GetManifestResourceStream(), you
will find one of its called function has unsafe signature:

internal virtual unsafe Stream GetManifestResourceStream(string name, ref
StackCrawlMark stackMark, bool skipSecurityCheck)

The resulting permission set is calculated using the all code paths. That's
why you're seeing some permission sets that are never used in your code

If your Web application contains code that requires more permissions than
are granted by a particular ASP.NET trust level, the easiest option is
customizing a policy file to grant the additional code access security
permission to your Web application. You can either modify an existing
policy file and grant additional permissions or create a new one based on
an existing policy file.

Another approach that does not require an update to ASP.NET code access
security policy is wrapping your resource access code in its own wrapper
assembly and configuring machine-level code access security policy to grant
the specific assembly the appropriate permission. Then you can sandbox the
higher-privileged code using the CodeAccessPermission.Assert method so you
do not have to change the overall permission grant of the Web application.
The Assert method prevents the security demand issued by the resource
access code from propagating back up the call stack beyond the boundaries
of the wrapper assembly.

For more information about above two different approaches, please refer to
following article:

#Using Code Access Security with ASP.NET

Walter Wang (wawang@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support

Get notification to my posts through email? Please refer to
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at

This posting is provided "AS IS" with no warranties, and confers no rights.


Relevant Pages

  • Re: security/strong name/zones clarification needed
    ... Does the Assert code go in its ... >>this AppDomain needs to be setup before your assembly can ... >>will recieve the permission grant you expect (in this ... All my assemblies are strong named. ...
  • Re: assembly doesn permit partially trustets calls
    ... To mitigate the risk, think very carefully about the permissions that you assign to the application running on the file share so that it permits exactly and only the request to satisfy the permission demand, block everything else. ... we can give all the assemblies in the ... Microsoft Online Community Support ...
  • Re: security/strong name/zones clarification needed
    ... Does the Assert code go in its ... >this AppDomain needs to be setup before your assembly can ... >will recieve the permission grant you expect (in this ... All my assemblies are strong named. ...
  • Re: security/strong name/zones clarification needed
    ... Dim zz As New System.Security.PermissionSet ... >> When assemblies are ... >>>needs to host the CLR, it creates an AppDomain, but due ... >>>will recieve the permission grant you expect (in this ...
  • Re: Custom Security Permission & Security Attribute troubles
    ... the permission and attribute in the "policy assemblies" list by using mscorcfg.msc ... > I'm trying to write a library that will allow me to add a custom ... > permission for my applications (let's call it ApplicationPermission ... > CodeAccessSecurityAttribute ...