WebPermissionAttribute.Connect 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置当前 WebPermissionAttribute 控制的 URI 连接字符串。
public:
property System::String ^ Connect { System::String ^ get(); void set(System::String ^ value); };
public string Connect { get; set; }
member this.Connect : string with get, set
Public Property Connect As String
属性值
一个字符串,包含当前 WebPermissionAttribute 控制的 URI 连接。
例外
当尝试设置该值时,Connect 不为 null
。 如果希望指定多个 Connect URI,请使用附加的特性声明语句。
示例
以下示例演示如何使用 WebPermissionAttribute 指定允许的 Connect 字符串。
public:
// Set the WebPermissionAttribute Connect property.
[method:WebPermission(SecurityAction::Deny,Connect="http://www.contoso.com/Private.htm")]
static void demoDenySite()
{
//Pass the security check.
CheckConnectPermission( "http://www.contoso.com/Public.htm" );
Console::WriteLine( "Public page has passed connect permission check" );
try
{
//Throw a SecurityException.
CheckConnectPermission( "http://www.contoso.com/Private.htm" );
Console::WriteLine( "This line will not be printed" );
}
catch ( SecurityException^ e )
{
Console::WriteLine( "Expected exception {0}", e->Message );
}
}
static void CheckConnectPermission( String^ uriToCheck )
{
WebPermission^ permissionToCheck = gcnew WebPermission;
permissionToCheck->AddPermission( NetworkAccess::Connect, uriToCheck );
permissionToCheck->Demand();
}
// Set the WebPermissionAttribute Connect property.
[WebPermission(SecurityAction.Deny, Connect=@"http://www.contoso.com/Private.htm")]
public static void demoDenySite()
{
//Pass the security check.
CheckConnectPermission("http://www.contoso.com/Public.htm");
Console.WriteLine("Public page has passed connect permission check");
try
{
//Throw a SecurityException.
CheckConnectPermission("http://www.contoso.com/Private.htm");
Console.WriteLine("This line will not be printed");
}
catch (SecurityException e) {
Console.WriteLine("Expected exception" + e.Message);
}
}
public static void CheckConnectPermission(string uriToCheck) {
WebPermission permissionToCheck = new WebPermission();
permissionToCheck.AddPermission(NetworkAccess.Connect, uriToCheck);
permissionToCheck.Demand();
}
' Set the WebPermissionAttribute Connect property.
<WebPermission(SecurityAction.Deny, Connect := "http://www.contoso.com/Private.htm")> _
Public Shared Sub CheckConnectPermission(uriToCheck As String)
Dim permissionToCheck As New WebPermission()
permissionToCheck.AddPermission(NetworkAccess.Connect, uriToCheck)
permissionToCheck.Demand()
End Sub
Public Shared Sub demoDenySite()
'Pass the security check.
CheckConnectPermission("http://www.contoso.com/Public.htm")
Console.WriteLine("Public page has passed Connect permission check")
Try
'Throw a SecurityException.
CheckConnectPermission("http://www.contoso.com/Private.htm")
Console.WriteLine("This line will not be printed")
Catch e As SecurityException
Console.WriteLine(("Expected exception" + e.Message))
End Try
End Sub
注解
应用于 WebPermissionAttribute 类时,此属性指定在类中接受的 URI 连接。 此属性为一次写入。