Export (0) Print
Expand All

WebPermissionAttribute Class

Specifies permission to access Internet resources. This class cannot be inherited.

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

[SerializableAttribute]
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Constructor|AttributeTargets::Method, AllowMultiple = true, 
	Inherited = false)]
public ref class WebPermissionAttribute sealed : public 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.

NoteNote:

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.

public:
   // 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 = (HttpWebRequest^)(WebRequest::Create( "http://www.contoso.com" ));
      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");
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft