﻿<?xml version="1.0" encoding="utf-8"?><Type Name="SecurityState" FullName="System.Security.SecurityState"><TypeSignature Language="C#" Value="public abstract class SecurityState" /><TypeSignature Language="ILAsm" Value=".class public auto ansi abstract beforefieldinit SecurityState extends System.Object" /><AssemblyInfo><AssemblyName>mscorlib</AssemblyName><AssemblyVersion>2.0.0.0</AssemblyVersion><AssemblyVersion>4.0.0.0</AssemblyVersion></AssemblyInfo><Base><BaseTypeName>System.Object</BaseTypeName></Base><Interfaces /><Docs><remarks><attribution license="cc4" from="Microsoft" modified="false" /><para>You must inherit from this class to provide a class that includes a property that specifies the security-sensitive action to be performed. The <see cref="T:System.Security.SecurityState" /> object that is instantiated from the derived class is passed to the <see cref="M:System.AppDomainManager.CheckSecuritySettings(System.Security.SecurityState)" /> method to determine whether the host allows that action to be performed. The default implementation of the <see cref="M:System.AppDomainManager.CheckSecuritySettings(System.Security.SecurityState)" /> method always returns false.  The method must be overridden to detect the actions that are allowed.</para><para>For example, if you want to access a Web camera in your library code, you would create a WebcamSecurityState object and call the <see cref="M:System.Security.SecurityState.EnsureState" /> 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.)</para><code>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);
}</code><para>To process the call the <see cref="T:System.AppDomainManager" /> must be made aware of WebcamSecurityState through an override of the <see cref="M:System.AppDomainManager.CheckSecuritySettings(System.Security.SecurityState)" /> method, as shown in the following example.</para><code>[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;
}
</code></remarks><summary><attribution license="cc4" from="Microsoft" modified="false" /><para>Provides a base class for requesting the security status of an action from the <see cref="T:System.AppDomainManager" /> object.</para></summary></Docs><Members><Member MemberName=".ctor"><MemberSignature Language="C#" Value="protected SecurityState ();" /><MemberSignature Language="ILAsm" Value=".method familyhidebysig specialname rtspecialname instance void .ctor() cil managed" /><MemberType>Constructor</MemberType><AssemblyInfo><AssemblyVersion>2.0.0.0</AssemblyVersion><AssemblyVersion>4.0.0.0</AssemblyVersion></AssemblyInfo><Parameters /><Docs><remarks>To be added.</remarks><summary><attribution license="cc4" from="Microsoft" modified="false" /><para>Initializes a new instance of the <see cref="T:System.Security.SecurityState" /> class. </para></summary></Docs></Member><Member MemberName="EnsureState"><MemberSignature Language="C#" Value="public abstract void EnsureState ();" /><MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void EnsureState() cil managed" /><MemberType>Method</MemberType><AssemblyInfo><AssemblyVersion>2.0.0.0</AssemblyVersion><AssemblyVersion>4.0.0.0</AssemblyVersion></AssemblyInfo><ReturnValue><ReturnType>System.Void</ReturnType></ReturnValue><Parameters /><Docs><remarks><attribution license="cc4" from="Microsoft" modified="false" /><para>The implementation of this method should be similar to the following example.</para><code>public override void EnsureState()
{
    if (!IsStateAvailable())
          throw new ApplicationException("WebcamSecurityState not available");
}
</code></remarks><summary><attribution license="cc4" from="Microsoft" modified="false" /><para>When overridden in a derived class, ensures that the state that is represented by <see cref="T:System.Security.SecurityState" /> is available on the host.</para></summary></Docs></Member><Member MemberName="IsStateAvailable"><MemberSignature Language="C#" Value="public bool IsStateAvailable ();" /><MemberSignature Language="ILAsm" Value=".method public hidebysig instance bool IsStateAvailable() cil managed" /><MemberType>Method</MemberType><AssemblyInfo><AssemblyVersion>2.0.0.0</AssemblyVersion><AssemblyVersion>4.0.0.0</AssemblyVersion></AssemblyInfo><ReturnValue><ReturnType>System.Boolean</ReturnType></ReturnValue><Parameters /><Docs><remarks><attribution license="cc4" from="Microsoft" modified="false" /><para><see cref="M:System.Security.SecurityState.IsStateAvailable" /> calls the <see cref="M:System.AppDomainManager.CheckSecuritySettings(System.Security.SecurityState)" /> method to determine whether the state that is represented by this class is available on the host. </para><para>See the <see cref="T:System.Security.SecurityState" /> class for an example implementation of the <see cref="M:System.AppDomainManager.CheckSecuritySettings(System.Security.SecurityState)" /> method.</para></remarks><summary><attribution license="cc4" from="Microsoft" modified="false" /><para>Gets a value that indicates whether the state for this implementation of the <see cref="T:System.Security.SecurityState" /> class is available on the current host. </para></summary><returns><attribution license="cc4" from="Microsoft" modified="false" /><para>true if the state is available; otherwise, false. </para></returns></Docs></Member></Members></Type>