WebPermissionAttribute Class
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
/** @attribute SerializableAttribute() */ /** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false) */ public final class WebPermissionAttribute extends CodeAccessSecurityAttribute
SerializableAttribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false) public final class WebPermissionAttribute extends CodeAccessSecurityAttribute
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.
/** @attribute WebPermission(SecurityAction.Deny, ConnectPattern =
"http://www\\.contoso\\.com/")
*/
public void Connect()
{
// Create a Connection.
HttpWebRequest myWebRequest =
(HttpWebRequest) WebRequest.Create("http://www.contoso.com");
Console.WriteLine("This line should never be printed");
} //Connect
System.Attribute
System.Security.Permissions.SecurityAttribute
System.Security.Permissions.CodeAccessSecurityAttribute
System.Net.WebPermissionAttribute
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Note