I have a window application which, when it runs from local pc, it executes with no error.
However, when I run the same exe from network e.g. \\Server\Share\ExeName.exe, it gives throws an exception as below.
<br />
Application attempted to perform an operation not allowed by the security policy. <br />
To grant this application the required permission, contact your....<br />
Request for permission of type 'System.Net.SockedtPermission, System, Version=2.0.0.0,<br />
Culture=neutral, PublicKeyToken=b77...' failed<br />
My code:
private void BindPort()
{
Socket winsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPHostEntry ipHostEntry = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostEntry.AddressList[0];
SocketPermission permitSocket = new SocketPermission(NetworkAccess.Connect, TransportType.Udp, ipAddress.ToString(), 1007);
permitSocket.Assert();
EP = new IPEndPoint(ipAddress, 1007);
try
{
winsock.Bind(EP);
}
catch (SocketException exp)
{
MessageBox.Show(exp.Message);
return false;
}
return true;
}