title: How can I find the role required when PrincipalPermissionAttribute demand fails?
body: <p>Within a web site I'm using the PrincipalPermission attribute to restrict access to certain methods. </p>
  
  <p>Here's a canoncial example:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Foo();
      }
  
      [System.Security.Permissions.PrincipalPermission(System.Security.Permissions.SecurityAction.Demand, Role = "Winners")]
      static void Foo()
      { }
  }
  </code></pre>
  
  <p>If the principal isn't in the role specified then the .net infrastructure throws a System.Security.SecurityException with the generic message "Request for principal permission failed".</p>
  
  <p>If the permission check fails I'd like to log what role the PrincipalPermission required. This will be really useful for our support staff who can then either assign the role to the user and/or monitor the logs to see if anything suspicious is happening. Clearly for security purposes the end user will still see a generic unauthorised message. I've trawled through the SecurityException itself but it doesn't have the "Role" anywhere in it. </p>
  
  <p>Is there anyway to get this information? </p>