mscorlib 2.0.0.0 4.0.0.0 System.Object

You must inherit from this class to provide a class that includes a property that specifies the security-sensitive action to be performed. The object that is instantiated from the derived class is passed to the method to determine whether the host allows that action to be performed. The default implementation of the method always returns false. The method must be overridden to detect the actions that are allowed.

For example, if you want to access a Web camera in your library code, you would create a WebcamSecurityState object and call the method to determine whether the host allows Web camera access, as shown in the following example. (You can find the code for WebcamSecurityState in the "Example" section.)

`WebcamSecurityState securityState = new WebcamSecurityState("Safe access to Webcam", WebcamSecurityOptions.SafeAccess); try { securityState.EnsureState(); // Allocate memory. } catch (ApplicationException e) { // Handle any exception that is thrown. System.Diagnostics.Debug.WriteLine(e.Message); }`

To process the call the must be made aware of WebcamSecurityState through an override of the method, as shown in the following example.

`[SecurityCritical] public override bool CheckSecuritySettings(System.Security.SecurityState securityState) { switch (securityState.ToString()) { case "WebcamSecurityState": { if ((securityState as WebcamSecurityState).Options == WebcamSecurityOptions.SafeAccess) return PromptUser((securityState as WebcamSecurityState).Description); return false; } } return false; } private bool PromptUser(string text) { // Replace the OpenFileDialog with a custom user prompt. OpenFileDialog o = new OpenFileDialog(); o.Title = text; if (o.ShowDialog() == DialogResult.OK) return true; else return false; }`

Provides a base class for requesting the security status of an action from the object.

- Constructor
  2.0.0.0
  4.0.0.0
  To be added.

  Initializes a new instance of the class.

- Method
  2.0.0.0
  4.0.0.0
  System.Void

  The implementation of this method should be similar to the following example.

  `public override void EnsureState() { if (!IsStateAvailable()) throw new ApplicationException("WebcamSecurityState not available"); }`

  When overridden in a derived class, ensures that the state that is represented by is available on the host.

- Method
  2.0.0.0
  4.0.0.0
  System.Boolean

  calls the method to determine whether the state that is represented by this class is available on the host.

  See the class for an example implementation of the method.

  Gets a value that indicates whether the state for this implementation of the class is available on the current host.

  true if the state is available; otherwise, false.