You work as the Microsoft.NET developer at Domain.com. The Domain.com network consists of a single Active Directory domain named Domain.com. All servers in the domain run Windows Server 2003. The creation, configuration and deployment of Remoting applications form part of your responsibilities at Domain.com.
A class named ObjectManager is defined in the ManagementServer namespace in an executable named ManagementServer.exe. The ObjectManager class is derived from MarshalByRefObject. You then create a client application named Client.exe. Client.exe does not have a reference to ManagerServer.exe. You need to keep in mind that there are a few technical requirements. These are:
1. The client application must execute with restricted permissions.
2. The ObjectManager must execute with unrestricted permissions. You now need to create an instance of ObjectManager in the client application.
What should you do? (Choose the correct code segment.)
A.
Dim remoteAssembly As Assembly =
Assembly.LoadFrom(“ManagementServer.exe”)
Dim level As PolicyLevel = PolicyLevel.CreateAppDomainLevel() Dim permissionSet As PermissionSet = New
PermissionSet(PemissionState.Unrestricted)
level.RootCodeGroup.PolicyStatement = New PolicyStatement(permissionSet) AppDomain.CurrentDomain.SetAppDomainPolicy(level)
Dim instance As Object =
remoteAssembly.CreateInstance(“ManagementServer.ObjectManager”)
B.
Dim level As PolicyLevel = PolicyLevel.CreateAppDomainLevel() Dim permissionSet As PermissionSet = New
PermissionSet(PermissionState.Unrestricted)
level.RootCodeGroup.PolicyStatement = New PolicyStatement(permissionSet) AppDomain.CurrentDomain.SetAppDomainPolicy(level)
Dim handle As ObjectHandle =
AppDomain.CurrentDomain.CreateInstanceFrom(“ManagementServer.exe”, “ManagementServer.ObjectManager”)
C.
Dim remoteDomain As AppDomain =
AppDomain.CreateDomain(“RemoteComponents”)
remoteDomain.ExeciteAssembly(“ManagementServer.exe”) Dim level As PolicyLevel = PolicyLevel.CreateAppDomainLevel() Dim permissionSet As PermissionSet = New
PermissionSet(PemissionState.Unrestricted)
level.RootCodeGroup.PolicyStatement = New PolicyStatement(permissionSet) remoteDomain.SetAppDomainPolicy(level)
Dim handle As ObjectHandle =
remoteDomain.CreateInstanceFrom(“ManagementServer.exe”, “ManagementServer.ObjectManager”)
D.
Dim level As PolicyLevel = PolicyLevel.CreateAppdomainLevel() Dim permissionSet As PermissionSet = New
PermissionSet(PermissionState.Unrestricted)
level.RootCodeGroup.PolicyStatement = New PolicyStatement(permissionSet) AppDomain.CurrentDomain.SetAppDomainPolicy(level)
Dim objectManager As ManagementServer.ObjectManager = New ManagementServer.ObjectManager()
Explanation:
ObjectManager should be created in a separate application domain because then it will allow unrestricted permissions to ObjectManager while still allowing the application to continue to run with restricted permissions. To create the application domain, you must call the CreateDomain method of the AppDomain class. ManagementServer.exe should then be loaded into the application domain by means of calling the ExecuteAssembly method of the AppDomain class. Then the security policy for the application domain should be set. Then you should create an instance of ObjectManager from the application domain by calling the CreateInstanceFrom method of theAppDomain class.
Incorrect answers:
A: The LoadFrom method loads an assembly into the current application domain, but due to the client application having a different requirement from the ObjectManager, you should load the ObjectManager into a different application domain. This means that you should not call the LoadFrom method of the Assembly class.
B: The CreateInstanceFrom method of the current AppDomain instance should not be called. It will then load an instance of ObjectManager into the current application domain. But because the client application has different requirement to that of ObjectManager, you should rather load ObjectManager into a different application domain.
D: The client application does not have a reference to ManagementServer.exe and thus you should not instantiate ObjectManager by calling its constructor. If you do it will load an ObjectManager instance into an application domain based on whether its configured to make use of Microsoft.Net Remoting or not.