I have to put my Program EXE in a server share, but when I try to open the
program a "System.Security.SecurityException" occures!
If I open my program in my computer no error occures...
Any clue?
Microsoft added these security settings to reduce misuse of software by
hackers.
Two things must be set:
* First you must tell the compiler that this program you created will use
Network access.
Default, .NET does not allow an executable to access network resources
(including open file dialog)
One way is to this can be done is by putting lines like these into you
assembly.cs:
[assembly:SecurityPermission(SecurityAction.RequestMinimum,
UnmanagedCode=true)] // Request to run unmanaged code
[assembly:FileIOPermission(SecurityAction.RequestMinimum,
Unrestricted=true)] // Request complete File IO functionality
[assembly:RegistryPermission(SecurityAction.RequestMinimum, All="*")] //
Request complet access to the registery key
[assembly:ZoneIdentityPermission(SecurityAction.RequestMinimum,Zone=Security
Zone.NoZone)] // Request unrestricted zone
* Second even if the program is allowed to run from network drives or open
files on network drives, the big boss of the computer that will run this
code on, must give enough rights to the program to actually run from network
or open network files. If you go to "control panel", "Choose Administrative
Tools", then you find something like "Microsoft .NET Framework 1.1 Wizards".
Double click on that and go to "Trust an assembly" and set the settings for
your program with your key (+strong name) to be fully trusted. An option to
change the trust "Adjust .NET security" for "Local intranet" might also be
put to fully trusted, but this is not wise to do so since you then accept
all .NET programs to run unrestricted.
In my opinion, generate a strong key (some program called sn.exe if I
remember correctly) ,
add this to your program BUT DO NOT DISTRIBUTE THIS TO OTHERS!
--> assembly.cs : [assembly: AssemblyKeyFile("..\\..\\MyKey.snk")]
Then you can tell the "Microsoft .NET Framework 1.1 Wizards". that all
programs with this strong key, ignoring assembly the version, are fully
trusted.
This way, you only have to register this once, and all your future upgrades
or other products with this key, will automatically be trusted for network
access.
It would be desirable that the security settings were not fixed in the
assembly.cs, but generated dynamically when needed.
Maybe other people have different techniques?
Hope this helps?