WebPermissionAttribute Class
Specifies permission to access Internet resources. This class cannot be inherited.
Assembly: System (in System.dll)
'Declaration <SerializableAttribute> _ <AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Constructor Or AttributeTargets.Method, AllowMultiple := True, _ Inherited := False)> _ Public NotInheritable Class WebPermissionAttribute _ Inherits CodeAccessSecurityAttribute 'Usage Dim instance As WebPermissionAttribute
WebPermissionAttribute allows you to declaratively specify which URI strings and regular expression strings your class can use.
The security information specified in the WebPermissionAttribute is stored in the metadata of the attribute target, which is the class to which WebPermissionAttribute is applied. The system accesses this information at run time. The System.Security.Permissions.SecurityAction passed to the constructor determines the allowable WebPermissionAttribute targets. The system uses the WebPermission returned by the CreatePermission method to convert the security information of the attribute target to a serializable form stored in metadata.
Note: |
|---|
WebPermissionAttribute is used only for Declarative Security. For Imperative Security, use the corresponding WebPermission. |
The following example demonstrates how to apply WebPermissionAttribute to a method.
' Deny access to a specific resource by setting the ConnectPattern property. <WebPermission(SecurityAction.Deny, ConnectPattern := "http://www\.contoso\.com/.*")> Public Sub Connect() ' Create a Connection. Dim myWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest) Console.WriteLine("This line should never be printed")
// Deny access to a specific resource by setting the ConnectPattern property.
[method:WebPermission(SecurityAction::Deny, ConnectPattern="http://www.contoso.com/")]
void Connect() {
// Create a Connection.
HttpWebRequest* myWebRequest =
dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"http://www.contoso.com"));
Console::WriteLine(S"This line should never be printed");
}
System.Attribute
System.Security.Permissions.SecurityAttribute
System.Security.Permissions.CodeAccessSecurityAttribute
System.Net.WebPermissionAttribute
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: