Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
C#
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;
}
Posted
Updated 12-Apr-11 21:18pm
v3
Comments
Toniyo Jackson 13-Apr-11 2:40am    
Added pre tag
Dalek Dave 13-Apr-11 3:18am    
Edited for Grammar and Readability.

1 solution

Hi,
When you run your application from your local computer it has the Full Trust permission set, thus you have no problem in working with sockets. But if you run you app from network it is a part of Local Intranet Zone which has the Local Intranet Permission set. In order to change the permission set for Local Intranet Zone, you should access the .NET Configuration tool (mscorcfg.msc), and change it manually. There is a great article here on codeproject that explain in a great detail Code Access Security within the .NET environment - Understanding .NET Code Access Security[^]
Regards
 
Share this answer
 
Comments
Dalek Dave 13-Apr-11 3:18am    
Good Call.
Naina Dhande 13-Apr-11 7:38am    
While going through "Understanding of .Net Code Access Security"
I had created the MyPermissionSet from Control Panel -> Administrative Tools -> Mrcrosoft Framework 1.1 Configuration tool
and tried to set the MyPermissionSet to MyCodeGroup Properties
After setting "This policy level will only have the permissions from the permission set associated with this code group." this option now I am unable to run Control Panel -> Administrative Tools -> Mrcrosoft Framework 1.1 Configuration tool. It gives me an error "MMC cannot initialize the snap-in"
What could be done to Fix this problem?

I am using VS 2008 on Windows XP.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900