WebPermissionAttribute(SecurityAction) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
以指定可以在這個類別上執行的安全性動作的值,初始化 WebPermissionAttribute 類別的新執行個體。
public:
WebPermissionAttribute(System::Security::Permissions::SecurityAction action);
public WebPermissionAttribute (System.Security.Permissions.SecurityAction action);
new System.Net.WebPermissionAttribute : System.Security.Permissions.SecurityAction -> System.Net.WebPermissionAttribute
Public Sub New (action As SecurityAction)
參數
- action
- SecurityAction
其中一個 SecurityAction 值。
例外狀況
action
不是有效的 SecurityAction 值。
範例
下列範例示範如何套用 WebPermissionAttribute 至方法。
public:
// Set the declarative security for the URI.
[WebPermission(SecurityAction::Deny,Connect="http://www.contoso.com/")]
void Connect()
{
// Throw an exception.
try
{
HttpWebRequest^ myWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://www.contoso.com/" ));
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception : {0}", e );
}
public void Connect()
{
// Throw an exception.
try
{
HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://www.contoso.com/");
}
catch(Exception e)
{
Console.WriteLine("Exception : " + e.ToString());
}
' 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
備註
SecurityAction傳遞至這個建構函式的值會指定可在此類別上執行的允許安全性動作。