exam questions

Exam 70-487 All Questions

View all questions & answers for the 70-487 exam

Exam 70-487 topic 5 question 1 discussion

Actual exam question from Microsoft's 70-487
Question #: 1
Topic #: 5
[All 70-487 Questions]

HOTSPOT -
Based on the security requirements, which line of code should you insert into the WebApiConfig file? To answer, select the appropriate options in the answer area.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
Scenario: The Web API must only accept one data format.
The MVC front-end layer and the Web API will communicate by using JSON.
The most common approach to support JSON only is to clear other formatters and leave only JsonMediaTypeFormatter around.
Given an instance of HttpConfiguration you'd simply clear all and re-add JsonMediaTypeFormatter: configuration.Formatters.Clear(); configuration.Formatters.Add(new JsonMediaTypeFormatter());
References:
http://www.strathweb.com/2013/06/supporting-only-json-in-asp-net-web-api-the-right-way/

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
abalone
Highly Voted 5 years, 8 months ago
Wrong answer. 1. Formatter 2. Remove 3. Formatter 4. XML source: https://vceguide.com/which-line-of-code-should-you-insert-into-the-webapiconfig-file/
upvoted 34 times
dosper
5 years, 8 months ago
Agree - https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/json-and-xml-serialization#removing-the-json-or-xml-formatter
upvoted 11 times
...
...
sti88
Most Recent 4 years, 8 months ago
I think the answer is correct, but is not the full solution. The full solution is to remove all format first before adding only Json back. Given an instance of HttpConfiguration you'd simply clear all and re-add JsonMediaTypeFormatter: configuration.Formatters.Clear(); configuration.Formatters.Add(new JsonMediaTypeFormatter());
upvoted 1 times
...
UweJ
5 years, 3 months ago
In https://docs.microsoft.com/de-de/aspnet/core/web-api/advanced/custom-formatters?view=aspnetcore-3.1 I found "The framework provides built-in input and output formatters for JSON and XML. " To fullfill the security requrement that only one media type is allowed and that the communication should be by JSON it shoud be 1. Formatter 2. Remove 3.Formatters 4.JsonFormatter
upvoted 2 times
Albeom
5 years, 2 months ago
And you just removed it
upvoted 7 times
...
zimzimzimma
4 years, 11 months ago
I think you mean 4.XmlFormatter
upvoted 4 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...