This documentation is archived and is not being maintained.

WebPermissionAttribute Constructor

Initializes a new instance of the WebPermissionAttribute class with a value that specifies the security actions that can be performed on this class.

[Visual Basic]
Public Sub New( _
   ByVal action As SecurityAction _
)
[C#]
public WebPermissionAttribute(
   SecurityAction action
);
[C++]
public: WebPermissionAttribute(
   SecurityAction action
);
[JScript]
public function WebPermissionAttribute(
   action : SecurityAction
);

Parameters

action
One of the SecurityAction values.

Exceptions

Exception Type Condition
ArgumentException action is not a valid SecurityAction value.

Remarks

The SecurityAction value passed to this constructor specifies the allowable security actions that can be performed on this class.

Example

[Visual Basic, C#, C++] The following example demonstrates how to apply WebPermissionAttribute to a method.

[Visual Basic] 

' Set the declarative security for the URI.
<WebPermission(SecurityAction.Deny, Connect := "http://www.contoso.com/")> _
Public Sub Connect()
   ' Throw an exception.     
   Try
      Dim myWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest)
   Catch e As Exception
      Console.WriteLine(("Exception : " + e.ToString()))
   End Try
End Sub 'Connect
 

[C#] 

  // Set the declarative security for the URI.
  [WebPermission(SecurityAction.Deny, Connect = @"http://www.contoso.com/")]
  public void Connect() 
  {
    // Throw an exception.   
    try
    {
      HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://www.contoso.com/");
    }
    catch(Exception e)
    {
      Console.WriteLine("Exception : " + e.ToString());
    }

[C++] 
// Set the declarative security for the URI.
[WebPermission(SecurityAction::Deny, Connect = S"http://www.contoso.com/")]
void Connect() {
   // Throw an exception.
   try {
      HttpWebRequest* myWebRequest =
         dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"http://www.contoso.com/"));
   } catch (Exception* e) {
      Console::WriteLine(S"Exception : {0}", e);
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

WebPermissionAttribute Class | WebPermissionAttribute Members | System.Net Namespace

Show: