I'm running the labs in MCTS 70-536 Training Kit chapter 11 about Code Access Security. I'm running XP Pro. The first lab creates an assembly which checks for different permissions and reports a message if they exist. However when I run it as \\\127.0.0.1\c$\ListPermissions.exe
it is supposed to recognize being in the intranet zone and use the intranet permission set. However all permissions seem to be granted. Does this behavior sound familiar to anyone? If not is there a way to check what zone the assembly thinks it is in when run from the share? If a specific part of this question is too vague, let me know and I will try to rephrase it.
I had the same problem.However I had tried something else. Instead of executing the program from various locations like from a shared folder or from the root of C drive, I have created an application domain and executed the code from my application domain with various Zone settings. Here is my code:
object[] hostEvidence = { new Zone(SecurityZone.Internet) };
Evidence appDomainEvidence = new Evidence(hostEvidence, null);
AppDomain d = AppDomain.CreateDomain("MyDomain", appDomainEvidence);
d.ExecuteAssembly("ListPermissions.exe");
When my zone is set to MyComputer the ListPermissions executes without giving any exeption and every permission returns true. However when I set my zone to internet or intranet the ExecuteAssembly line starts to give exeptions which actually made me happy. At least at some point it works.
From my understanding what book says when you run your application from different locations the CLR sees that the running code has a different evidence and assings the assembly to a different code group like mycomputer or internet. However at least with my configuration it is not like that, and another forum it is concluded that with .NET framework 3.5 a running assembly from a shared folder does not have the exact evidence as an assembly running from internet zone. http://social.msdn.microsoft.com/Forums/en/clr/thread/5f5f0925-64fc-4fc8-9be3-d077d27d2554 I actually do not know the exact sollution which makes the program executes as it does in the book. Just want to share that with a created custom application domain the code works as it is supposed to do.
Hope this helps
Thanks