Ragid said:
How do I know programatically if the PC where my application runs is on a
local LAN or on the Internet?
The question is not terribly clear. The PC where the application runs,
form the point of view of the application, is always the local machine. It
does not even have to be connected to a network, or if it is connected to a
LAN, the LAN itself could then have a gateway into the Internet.
The question that is more relevant from the point of view of .Net is
whether the executable file was started from a server in the local intranet
or from a server in the internet zone. The executable is then downloaded
into the memory of the local PC, and it *runs* in the local PC. This
distinction is relevant because the CAS permissions will be different
depending on the zone from which the file was downloaded. You can detect the
zone in your code by performing a Demand for the needed permissions. This
can be done with some code similar to the following (untested):
PermissionSet pset = GetNamedPermissionSet("LocalIntranet");
try
{
myPerm.Demand();
}
catch (SecurityException)
{
//We are NOT in the LocalIntranet zone.
}
....
private static PermissionSet GetNamedPermissionSet(string name)
{
IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();
while (policyEnumerator.MoveNext())
{
PolicyLevel currentLevel =
(PolicyLevel)policyEnumerator.Current;
if (currentLevel.Label == "Machine")
{
NamedPermissionSet copy =
currentLevel.GetNamedPermissionSet(name);
return (PermissionSet)copy;
}
}
return null;
}