private void CheckPermissionAllowed(string configKey, bool requirePermission, bool isTrustedWithoutAptca) {
//
// Demand unrestricted ConfigurationPermission if the section requires it
//
if (requirePermission) {
try {
UnrestrictedConfigPermission.Demand();
}
catch (SecurityException e) {
//
// Add a nice error message that includes the sectionName and explains
// how to use the requirePermission attribute.
//
throw new SecurityException(
SR.GetString(SR.ConfigurationPermission_Denied, configKey),
e);
}
}
//
// Ensure that the recepient isn't receiving an object they otherwise
// wouldn't be able to create due to Aptca.
//
if (isTrustedWithoutAptca && !Host.IsFullTrustSectionWithoutAptcaAllowed(this)) {
throw new ConfigurationErrorsException(SR.GetString(SR.Section_from_untrusted_assembly, configKey));
}
}