Compartilhar via


WebPermissionAttribute.Accept Propriedade

Definição

Obtém ou define a cadeia de caracteres do URI aceita pelo WebPermissionAttribute atual.

public:
 property System::String ^ Accept { System::String ^ get(); void set(System::String ^ value); };
public string Accept { get; set; }
member this.Accept : string with get, set
Public Property Accept As String

Valor da propriedade

Uma cadeia de caracteres que contém o URI aceito pelo atual WebPermissionAttribute.

Exceções

Accept não é null quando você tentar definir o valor. Se você quiser especificar mais de um URI Accept, use uma instrução de declaração de atributo adicional.

Exemplos

O exemplo a seguir demonstra como usar WebPermissionAttribute para especificar uma cadeia de caracteres permitida Accept .

public:
   // Deny access to a specific resource by setting the Accept property.
   [method:WebPermission(SecurityAction::Deny,Accept="http://www.contoso.com/Private.htm")]

   static void CheckAcceptPermission( String^ uriToCheck )
   {
      WebPermission^ permissionToCheck = gcnew WebPermission;
      permissionToCheck->AddPermission( NetworkAccess::Accept, uriToCheck );
      permissionToCheck->Demand();
   }

   static void demoDenySite()
   {
      // Pass the security check when accessing allowed resources.
      CheckAcceptPermission( "http://www.contoso.com/" );
      Console::WriteLine( "Public page has passed Accept permission check" );

      try
      {
         // Throw a SecurityException when trying to access not allowed resources.
         CheckAcceptPermission( "http://www.contoso.com/Private.htm" );
         Console::WriteLine( "This line will not be printed" );
      }
      catch ( SecurityException^ e ) 
      {
         Console::WriteLine( "Exception trying to access private resource: {0}", e->Message );
      }
   }

// Deny access to a specific resource by setting the Accept property.
[WebPermission(SecurityAction.Deny, Accept=@"http://www.contoso.com/Private.htm")]

public static void CheckAcceptPermission(string uriToCheck) 
{
    WebPermission permissionToCheck = new WebPermission();
    permissionToCheck.AddPermission(NetworkAccess.Accept, uriToCheck);
    permissionToCheck.Demand();
}

public static void demoDenySite() 
{
    //Pass the security check when accessing allowed resources.
    CheckAcceptPermission("http://www.contoso.com/");
    Console.WriteLine("Public page has passed Accept permission check");

    try 
    {
        //Throw a SecurityException when trying to access not allowed resources.
        CheckAcceptPermission("http://www.contoso.com/Private.htm");
        Console.WriteLine("This line will not be printed");
    }
    catch (SecurityException e) 
    {
        Console.WriteLine("Exception trying to access private resource:" + e.Message);
    }
 }

 ' Deny access to a specific resource by setting the Accept property.

<WebPermission(SecurityAction.Deny, Accept := "http://www.contoso.com/Private.htm")>  _
   Public Shared Sub CheckAcceptPermission(uriToCheck As String)
   Dim permissionToCheck As New WebPermission()
   permissionToCheck.AddPermission(NetworkAccess.Accept, uriToCheck)
   permissionToCheck.Demand()
End Sub


Public Shared Sub demoDenySite()
   ' Pass the security check when accessing allowed resources.
   CheckAcceptPermission("http://www.contoso.com/Public.htm")
   Console.WriteLine("Public page has passed Accept permission check")
   Try
      'Throw a SecurityException when trying to access not allowed resources.
      CheckAcceptPermission("http://www.contoso.com/Private.htm")
      Console.WriteLine("This line will not be printed")
   Catch e As SecurityException
      Console.WriteLine(("Exception trying to access private resource:" + e.Message))
   End Try
End Sub

Comentários

Ao aplicar WebPermissionAttribute à sua classe, essa propriedade especifica qual cadeia de caracteres de URI será aceita para uso em sua classe. Essa permissão é aplicada quando o sistema de segurança chama CreatePermission. Essa propriedade é write-once.

Aplica-se a

Confira também