// S1006/ImperativeSecurity public static void Work() { NamedPermissionSet permissions = new NamedPermissionSet("Custom"); permissions.Demand(); SecureClass.RevertDocument(); }
public static void Access() { // This security check fails if the caller // does not have full trust. NamedPermissionSet pset= new NamedPermissionSet("FullTrust"); // This try-catch block shows the caller's permissions. // Correct code would either not catch the exception, // or would rethrow it. try { pset.Demand(); } catch (SecurityException e) { Console.WriteLine("Demand for full trust:{0}", e.Message); } // Call the type that requires full trust. // Violates rule AptcaMethodsShouldOnlyCallAptcaMethods. ClassRequiringFullTrust.DoWork(); }