I have done all the steps in my Microsoft Lab book (70-536) Lab 6.3
My problem is with the following code:
static void Main(string[] args)
{
MainClass objMain = new MainClass();
Console.WriteLine("----VERIFYING TRUST LEVEL ----");
objMain.FindPermissionLevel();
Console.Read();
}
I looked on MSDN and could not find an assembly reference to get MainClass to work, also there was no class 'MainClass' defined in the example, here is the example right out of the book:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Security;
using System.Security.Policy;
using System.Collections;
namespace WorkingOnApplicationDomainPrivileges
{
class Program
{
static void Main(string[] args)
{
MainClass objMain = new MainClass();
Console.WriteLine("----VERIFYING TRUST LEVEL ----");
objMain.FindPermissionLevel();
Console.Read();
}
private void FindPermissionLevel()
{
bool isFullTrust = true;
IEnumerator policy = SecurityManager.PolicyHierarchy();
while (policy.MoveNext())
{
PolicyLevel currentLevel = (PolicyLevel)policy.Current;
CodeGroup codeGrp = currentLevel.ResolveMatchingCodeGroups(Assembly.GetExecutingAssembly().Evidence);
isFullTrust = IsFullTrustPolicyLevel(codeGrp, currentLevel);
if (isFullTrust)
{
Console.WriteLine("/t Policy Level: " + currentLevel.Label + " - Full trust mode");
}
else
{
Console.WriteLine("/t Policy Level: " + currentLevel.Label + " - Not in trust mode");
}
}
}
private bool IsFullTrustPolicyLevel(CodeGroup group, PolicyLevel level)
{
bool success = false;
NamedPermissionSet nps = level.GetNamedPermissionSet(group.PermissionSetName);
if (nps.Name == "FullTrust")
{
success = true;
}
else
{
success = false;
}
return success;
}
}
}
My question is how do I wright a MainClass to get this to work?
ps this is done in a console application.
There have been so many errors in these books, some of which I was able to solve myself, as for the rest I have only CodeProject to thank.
Both Microsoft, and the publishing house Wiley provide no support for the poor quality of these books.
Thanks in advance...