[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method)] |
[SocketPermission(SecurityAction.Assert, Access = "Connect", Host = "192.168.144.238", Port = "All", Transport = "All")] [SocketPermission(SecurityAction.Deny, Access = "Connect", Host = "192.168.144.239", Port = "All", Transport = "All")] public String GetDate() { // Gets the current date from the remote date server. try { int bytesReceived; byte[] getByte = new byte[100]; Socket mysocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { mysocket.Connect(new IPEndPoint(IPAddress.Parse("192.168.144.239"), 13)); } catch (SecurityException e){ Console.WriteLine("SecurityException (expected)" + e.Message); } mysocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); mysocket.Connect(new IPEndPoint(IPAddress.Parse("192.168.144.238"), 13)); bytesReceived = mySocket.Receive( getByte, getByte.Length, 0 ); return asciiEncoding.GetString( getByte, 0, bytesReceived ); } catch(Exception e) { Console.WriteLine(e.Message); return ""; } }
ctor #1 | Initializes a new instance of the SocketPermissionAttribute class with the specified SecurityAction value. |
Access | Read-write Gets or sets the network access method allowed by this SocketPermissionAttribute. |
Action (inherited from System.Security.Permissions.SecurityAttribute) |
Read-write See base class member description: System.Security.Permissions.SecurityAttribute.Action Gets or sets a security action. |
Host | Read-write Gets or sets the DNS host name or IP address specified by this SocketPermissionAttribute. |
Port | Read-write Gets or sets the port number associated with this SocketPermissionAttribute. |
Transport | Read-write Gets or sets the TransportType specified by this SocketPermissionAttribute. |
TypeId (inherited from System.Attribute) |
Read-only See base class member description: System.Attribute.TypeId When implemented in a derived class, gets a unique identifier for this Attribute. |
Unrestricted (inherited from System.Security.Permissions.SecurityAttribute) |
Read-write See base class member description: System.Security.Permissions.SecurityAttribute.Unrestricted Gets or sets a value indicating whether full (unrestricted) permission to the resource protected by the attribute is declared. |
CreatePermission | Overridden: Creates and returns a new instance of the SocketPermission class. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetHashCode (inherited from System.Attribute) |
See base class member description: System.Attribute.GetHashCode Returns the hash code for this instance. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
IsDefaultAttribute (inherited from System.Attribute) |
See base class member description: System.Attribute.IsDefaultAttribute When overridden in a derived class, returns an indication whether the value of this instance is the default value for the derived class. |
Match (inherited from System.Attribute) |
See base class member description: System.Attribute.Match When overridden in a derived class, returns a value indicating whether this instance equals a specified object. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public SocketPermissionAttribute( |
action
[SocketPermission(SecurityAction.Assert, Access = "Connect", Host = "192.168.144.238", Port = "All", Transport = "All")] [SocketPermission(SecurityAction.Deny, Access = "Connect", Host = "192.168.144.239", Port = "All", Transport = "All")] public String GetDate() { // Gets the current date from the remote date server. try { int bytesReceived; byte[] getByte = new byte[100]; Socket mysocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { mysocket.Connect(new IPEndPoint(IPAddress.Parse("192.168.144.239"), 13)); } catch (SecurityException e){ Console.WriteLine("SecurityException (expected)" + e.Message); } mysocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); mysocket.Connect(new IPEndPoint(IPAddress.Parse("192.168.144.238"), 13)); bytesReceived = mySocket.Receive( getByte, getByte.Length, 0 ); return asciiEncoding.GetString( getByte, 0, bytesReceived ); } catch(Exception e) { Console.WriteLine(e.Message); return ""; } }
public string Access {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentException | The SocketPermissionAttribute.Access property is not null when you attempt to set the value. If you wish to specify more than one Access method, use an additional attribute declaration statement. |
public SecurityAction Action {get; set;}
|
public string Host {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentException | SocketPermissionAttribute.Host is not null when you attempt to set the value. If you wish to specify more than one host, use an additional attribute declaration statement. |
public string Port {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentException | The SocketPermissionAttribute.Port property is null when attempt to set the value. If you wish to specify more than one port, use an additional attribute declaration statement. |
public string Transport {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentException | SocketPermissionAttribute.Transport is not null when you attempt to set the value. If you wish to specify more than one transport type, use an additional attribute declaration statement. |
public virtual object TypeId {get;}
|
public bool Unrestricted {get; set;}
|
public override IPermission CreatePermission(); |
~SocketPermissionAttribute(); |
public override int GetHashCode(); |
public Type GetType(); |
public virtual bool IsDefaultAttribute(); |
The implementation of this method in a derived class compares the value of this instance to a standard, default value obtained by some means, then returns a Boolean value that indicates whether the value of this instance is equal to the standard. The standard value is typically coded as a constant in the implementation, or stored programmatically in a field used by the implementation.
obj
protected object MemberwiseClone(); |
public virtual string ToString(); |