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传递给此构造函数的值指定可对此类执行的允许安全操作。