WebPermissionAttribute.AcceptPattern Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets a regular expression pattern that describes the URI accepted by the current WebPermissionAttribute.

Namespace:   System.Net
Assembly:  System (in System.dll)

Public Property AcceptPattern As String

Property Value

Type: System.String

A string containing a regular expression pattern that describes the URI accepted by the current WebPermissionAttribute. This string must be escaped according to the rules for encoding a System.Text.RegularExpressions.Regex constructor string.

Exception Condition
ArgumentException

AcceptPattern is not null when you attempt to set the value. If you wish to specify more than one Accept URI, use an additional attribute declaration statement.

When applying WebPermissionAttribute to your class, this property specifies what regular expression string will be accepted for use within your class. This property is write-once.

The following example demonstrates how to use WebPermissionAttribute to specify an allowable AcceptPattern.

<WebPermission(SecurityAction.Deny, AcceptPattern := "http://www\.contoso\.com/Private/.*")> _
  Public Shared Sub       CheckAcceptPermission(uriToCheck As String)
     Dim re As New Regex("http://www\.contoso\.com/Public/.*")
     Dim con As New WebPermission(NetworkAccess.Connect, re)
     con.Assert()
     Dim permissionToCheck As New WebPermission()
     permissionToCheck.AddPermission(NetworkAccess.Accept, uriToCheck)
     permissionToCheck.Demand()
  End Sub 'CheckAcceptPermission


  Public Shared Sub demoDenySite()
     'Passes a security check.
     CheckAcceptPermission("http://www.contoso.com/Public/page.htm")
     Console.WriteLine("Public page has passed Accept permission check")

     Try
        'Throws a SecurityException.
        CheckAcceptPermission("http://www.contoso.com/Private/page.htm")
        Console.WriteLine("This line will not be printed")
     Catch e As SecurityException
        Console.WriteLine(("Expected exception" + e.Message))
     End Try
  End Sub 'demoDenySite


.NET Framework
Available since 1.1
Return to top
Show: