Επεξεργασία

Κοινή χρήση μέσω


SectionInformation.RequirePermission Property

Definition

Gets a value that indicates whether the associated configuration section requires access permissions.

public:
 property bool RequirePermission { bool get(); void set(bool value); };
public bool RequirePermission { get; set; }
member this.RequirePermission : bool with get, set
Public Property RequirePermission As Boolean

Property Value

true if the requirePermission attribute is set to true; otherwise, false. The default is true.

Exceptions

The selected value conflicts with a value that is already defined.

Examples

The following example shows two possible trust levels for a Web application when the RequirePermission property of the appSettings section is true.

<system.web>
   // With the following trust value
   // the code below works.
  <trust level="Full" />
</system.web>

<system.web>
  // With the following trust value
  // the code below does not work.
  <trust level="Medium" />
</system.web>

The following example shows code that runs without errors when the trust level is set to full. Otherwise, the code results in an error.

AppSettingsSection apSection =
  ConfigurationManager.GetSection("appSettings") as AppSettingsSection;

NameValueCollection apSectionCollection =
  ConfigurationManager.AppSettings;
Dim apSection As AppSettingsSection = _
  TryCast(ConfigurationManager.GetSection("appSettings"),
    AppSettingsSection)

  Dim apSectionCollection As NameValueCollection = _
    ConfigurationManager.AppSettings

Remarks

When RequirePermission is set to true, the GetSection methods are restricted by the trust level setting of the application. This means that methods or properties that allow access to configuration section handlers are restricted by the trust level set for the Web application.

Note

Because high and full trust are the only levels that allow access to files outside the current application domain, an application can use configuration section handlers only at these trust levels.

When RequirePermission is set to false, the access to the configuration data is not restricted by the application's trust level settings.

Note

The appropriate file ACL (Access Control List) permissions are still required, regardless of the RequirePermission setting. ACL permissions determine who can access the configuration file.

Applies to