Microsoft Developing ASP.NET MVC 4 Web Applications - 70-486 Exam Practice Test

You are developing an ASP.NET Core MVC web application that generates html-based reports each day. The reports are placed in a folder named Results in the root of the application.
The application must run on both Windows and Linux.
You need to ensure that reports can be downloaded.
How should you complete the code? To answer, drag the appropriate code segments to the correct locations. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.
NOTE: Each correct selection is worth one point.
Correct Answer:

Explanation:
Box 1: PhysicalFileProvider
Box 2: Directory
Code example.
There are three types of IFileProvider Implementations -
Physical File Provider - it is used to access the actual or physical file of the system Embedded File Provider - it is used to access files that are embedded in assemblies Composite File Provider - it is used to provide combine access to the files from one or more providers.
Box 3: Pathstring
Code example:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
RequestPath = new PathString("/StaticFiles")
});
References:
https://jakeydocs.readthedocs.io/en/latest/fundamentals/static-files.html
Customers download videos by using HTTP clients that support various content encodings.
You need to configure caching on the DownloadVideo action to maximize performance.
Which attribute should you add?
Correct Answer: E
You are preparing to deploy an ASP.NET MVC web application to an Microsoft Azure App Services Web App. The application was built by another team, and the source code cannot be changed.
The application depends on a specific set of files to operate correctly. These files must exist on a local disk.
You need to ensure that the application works correctly.
Which two tasks should you perform? Each correct answer presents part of the solution.
NOTE: Each correct selection is worth one point
Correct Answer: B,D
You are developing an ASP.NET MVC application that will be deployed on a web farm.
Passwords must be stored in the web.config file and must not be readable or in a format that is easily decodable.
You need to encrypt the passwords that are stored in the web.config file.
Which command-line tool should you use?
Correct Answer: A
Explanation: Only visible for ExamsLabs members. You can sign-up / login (it's free).
You are developing an ASP.NET Core MVC API microservice that calculates and provides loan rates. The microservice is configured to listen on port 6000.
The microservice must be deployed to a Docker container in Windows. You add a file named Dockerfile to the microservice project.
You need to build the Docker image.
In which order should you perform the actions? To answer, move all actions from the list of actions to the answer area and arrange them in the correct order.
Correct Answer:

1 - Use the FROM instruction to define the base image.
2 - Use the WORKDIR instruction to define the working directory.
3 - Use the COPY instruction to copy the source code into the image and then use the RUN instruction to restore NuGet packages.
4 - Use the ENTRYPOINT instruction to use the container as an executable.
5 - Use the EXPOSE instruction to specify the listen port and build and run the application.
Explanation:
Step 1: Use the FROM instruction to define the base image.
FROM creates a layer from the ubuntu Docker image.
The first FROM command is an important Docker command, allowing you to pull dependencies from other images.
Step 2: Use the WORKDIR instruction to define the working directory
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.
Step 3: Use the COPY instructions to copy the source code into the image and then use the RUN instruction to restore NuGet packages.
Step 4: Use the ENTRYPOINT instruction to use the container as an executable Step 5: Use the EXPOSE instruction to specify the listen port and build and run the application.
References:
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
You are developing an ASP.NET MVC application.
Before an action is executed, information about the action must be written to a log. After results are returned, information about the results also must be written to the log.
You need to log the actions and results.
You have the following code:

Which code segments should you include in Target 1, Target 2 and Target 3 to implement the LogActionFilter class? (To answer, select the appropriate option from the drop-down list in the answer area.)
Correct Answer:

Explanation:
Target 1: IActionFilter
MVC3 introduced a completely new pattern to configure filters for controllers and its actions. While injection of filter attributes is still supported it is recommended using this new pattern for filter configuration because it has the advantage to support constructor injection and does not require the InjectAttribute anymore.
First of all you have to create your filter class by implementing one of the filter interfaces e.g. IActionFilter.
Target 2: public void OnActionExecuting(ActionExecutingContext filterContext) Target 3: public void OnActionExecuted(ActionExecutedContext filterContext) References:
Note: This question is part of a series of questions that present the same scenario. Each question in the series contains a unique solution that might meet the stated goals. Some questions sets might have more than one correct solution, while others might not have a correct solution.
After you answer a question in this section, you will NOT be able to return to it. As a result, these questions will not appear in the review screen.
You develop an ASP.NET Core MVC web application. You have a legacy business system that sends data to the web application by using Web API. The legacy business system uses proprietary data formats.
You need to handle the proprietary data format.
Solution: Add a custom formatter class to the Web API and implement the IInputFormatter interface.
Does the solution meet the goal?
Correct Answer: A
Explanation: Only visible for ExamsLabs members. You can sign-up / login (it's free).
You are developing an ASP.NET MVC application that will be hosted on Microsoft Azure. The application includes the StackExchange.Redis client package. A variable named CacheConnectionConfiguration stores the cache endpoint URL and the password to connect to the cache.
The application must store a user's color selection by using the Azure Redis cache. The cached value must expire after 90 minutes. You need to cache the user's color selection.
How should you complete the relevant code? To answer, choose the appropriate code segment from each list in the answer area.
Correct Answer:

Explanation:
Box 1: var cache = connection.GetDatabase():
Once the connection is established, return a reference to the redis cache database by calling the ConnectionMultiplexer.GetDatabase method.
Box 2: cache StringSet("color", colorSelection,TimeSpan.FromMinutes(90)); The TimeSpanFromMinutes method returns a TimeSpan that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.
Example: The following code snippet shows how to set an expiration time of 90 minutes on a key.
// Add a key with an expiration time of 90 minutes
await cache.StringSetAsync("data:key1", 99, TimeSpan.FromMinutes(90));
References: https://docs.microsoft.com/en-us/azure/redis-cache/cache-dotnet-how-to-use-azure-redis-cache
https://msdn.microsoft.com/en-us/library/system.timespan.fromminutes(v=vs.110).aspx
You are designing a ASP.NET Core MVC application that runs on the Microsoft Azure platform.
The application must store a small amount of information that is shared across all users and does not change frequently.
You need to configure the application to meet the requirements.
Which server-side state management options will achieve the goal? Each correct answer presents a complete solution.
NOTE: Each correct selection is worth one point.
Correct Answer: A,D
You are developing a NuGet package that will be used by applications that target multiple .NET runtime environments.
You need to include NuGet package references within application project files.
What should you use?
Correct Answer: B
Explanation: Only visible for ExamsLabs members. You can sign-up / login (it's free).
You are developing an ASP.NET MVC application to display product information. The application has two views. The first view displays a list of product names. When you select a product name, the second view shows detailed information for the product that is selected. The product detail view receives a query string value that contains as identifier for the product that is selected.
The product controller for the application has the following requirements:

You need to implement the product controller.
How should you complete the relevant code? To answer, select the appropriate code from each list in the answer area.
Correct Answer:

Explanation:
Box 1: [OutputCache(Duration = 86400, VaryByParam ="none")]
The list of products must be cached daily. One day is 86400 seconds (60*60*24).
Note: The Duration parameter is the time, in seconds, that the page or user control is cached. Setting this attribute on a page or user control establishes an expiration policy for HTTP responses from the object and will automatically cache the page or user control output.
Box 2: [OutputCache(Duration = 3600, VaryByParam ="id")]
The product details view must cache data for one hour, based on the product that is selected. One hour is 3600 seconds (60* 60).
References: https://msdn.microsoft.com/en-us/library/hdxfb6cy(v=vs.100).aspx
You are developing an ASP.NET MVC application that enables you to edit and save a student object.
The application must not retrieve student objects on an HTTP POST request.
You need to implement the controller.
Which code segment should you use? (Each correct answer presents a complete solution. Choose all that apply.)
Correct Answer: C,D