You work as the application developer at Domain.com. Domain.com uses Visual Studio.NET 2005 as its application development platform.
You use a Windwos XP Professional client computer named Certkiller -WS554 as your development computer.
You are developing a .NET Framework 2.0 application on Certkiller -WS554. You write the following code in the application line numbers are for reference only:
01: Public Function ProcCount() As Integer
02: Dim envPerm As EnvironmentPermission = _
03: New EnvironmentPermission( _
04: EnvironmentPermissionAccess.Read, _
05: “NUMBER_OF_PROCESSORS”)
06: ‘Add code segment here
07: Return Environment.ProcessorCount
08: End Function
The ProcCount method in the code will be used to return the number of processors on the computer running the code and the implementation of the method is completely transparent to the callers of the methods. You ensured that the ProcCount method has been granted permission to access environment variables and the callers to the code may not have permission to access the variables. The classes in the other assemblies are required to be able to successfully call the ProcCount method. You must add code at line 06 to override the security check whilst you ensure that any code you write does not affect the permissions that your code already has.
What code segment should you add?
A.
envPerm.PermitOnly()
B.
envPerm.Demand()
C.
encPerm.Deny()
D.
envPerm.Assert()
Explanation:
The envPerm.Assert() method should be used in the scenario because the method allows your code and any code that you call to perform actions that your code has permissions to perform however the callers may not have permissions to perform.
Incorrect Answers:
A: The PermitOnly method should not be used in the scenario because it will result to the same action as calling Deny on all permissions other than the permission P and this will affect other permissions.
B: This method should not be considered for use in the scenario because the Demand method requires all the callers to have permissions to perform the specific action.
C: The Deny method should not be considered for usage in the scenario because the method will explicitly cause the Permission P to be denied and you are required to ensure permissions are applied to the code.
Correct answer is D