exam questions

Exam 70-486 All Questions

View all questions & answers for the 70-486 exam

Exam 70-486 topic 1 question 179 discussion

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

HOTSPOT -
You are developing an ASP.NET Core application. You have the following code:

You create a folder named Content in your project. You add a controller action that uses authorization and returns a FileResult object.
The application must meet the following requirements:
✑ Use Kestrel as the server.
✑ Serve static files from the wwwroot folder and publicly cache the files for five minutes.
✑ Serve static from the Content folder to authorized users only.
✑ Serve a default.html file from the wwwroot folder.
You need to configure the application.
How should you complete the code? To answer, select the appropriate options in the answer area.
NOTE: Each correct selection is worth one point.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
Box 1: UseStaticFiles -
For the wwwroot folder. We serve static files from the wwwroot folder

Box 2: UseStaticFiles -

Box 3: UseStaticFiles -
Serve static from the Content folder to authorized users only.
Note the two app.UseStaticFiles calls. The first one is required to serve the CSS, images and JavaScript in the wwwroot folder (Box 1), and the second call (box 3) for directory browsing of the content folder
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

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
Piggas
Highly Voted 5 years, 8 months ago
First Option should be UseDefaultFiles to serve a default. Other 2 options useStaticFiles is correct. Unless the question asked that files can be browsed, but then the code for thir option might looked different. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-3.0
upvoted 22 times
ex
5 years, 6 months ago
Agreed. Default, Static, Static
upvoted 13 times
...
Janibaldo
5 years, 3 months ago
app.UseDefaultFiles() – This middleware allows to serve default files. This will search the wwwroot folder for following files. index.html index.htm default.html default.htm
upvoted 3 times
tanujgyan
5 years ago
This is correct default static static. Refer to link by piggas
upvoted 2 times
...
...
...
zimzimzimma
Highly Voted 4 years, 11 months ago
If it wouldn't be for sites and a community like this, I would quickly lose my sanity. Many of these questions are (deliberately?) botched.
upvoted 9 times
...
ParkPalaceJoe
Most Recent 4 years, 7 months ago
did not mention setting default page, so the correct answer is just app.UserStaticFilters() for all files
upvoted 1 times
...
mr_
4 years, 12 months ago
'The UseDefaultFiles configures the DefaultFiles middleware which is a part of StaticFiles middleware. This will automatically serve html file named default.html, default.htm, index.html or index.htm on the http request http://localhost:<port>. The above example will display default.html file on http://localhost:<port> as shown below.' Ref: https://www.tutorialsteacher.com/core/aspnet-core-static-file So: UseDefaultFiles; UseStaticFiles; UseStaticFiles.
upvoted 8 times
...
Dev666
5 years ago
should be Default, Static, Static. see https://aspnetcore.readthedocs.io/en/latest/fundamentals/static-files.html
upvoted 4 times
...
Aghie
5 years, 9 months ago
im sorry. I cant update my comment. the app.UseDirectoryBrowser() only has DirectoryBrowserOptions options. so the right answer for the third box is really .UseStaticFiles
upvoted 2 times
...
Aghie
5 years, 9 months ago
I take my comment back. the third one should be UseDirectoryBrowser().
upvoted 1 times
Dev666
5 years ago
wrong see https://aspnetcore.readthedocs.io/en/latest/fundamentals/static-files.html should be Default, Static, Static.
upvoted 3 times
...
...
Aghie
5 years, 9 months ago
All three UseStaticFiles are right. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-2.2
upvoted 4 times
...
yayopojif
5 years, 9 months ago
The third option should be UseDirectoryBrowser: https://jakeydocs.readthedocs.io/en/latest/fundamentals/static-files.html#enabling-directory-browsing
upvoted 3 times
founderDev
5 years, 4 months ago
correct answer is Static,static,static. first line is : app.UseStaticFiles(); // For the wwwroot folder
upvoted 3 times
tanujgyan
5 years ago
The second box usestaticfiles covers this option Serve static files from the wwwroot folder and publicly cache the files for five minutes.
upvoted 1 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 ...