Developing ASP.NET MVC Web Applications — Question 153
You are developing an ASP.NET Core MVC web application that provides assets to external websites including images, JavaScript scripts and text files.
The external websites must be able to make full use of assets provided to them by the web application, including JavaScript asynchronous HTTP requests.
Pages that refer to the images and text files do not load. External websites are unable to use assets.
You need to resolve the issues.
What should you do?
Answer options
- A. Add a MVC controller and action to load the files from the folder.
- B. In the startup Configure method, call IApplicationBuilder. Use StaticFiles for the folder that contains the files.
- C. In the startup ConfigureServices method, call IServiceCollection. Add DirectoryBrowser for the folder that contains the files.
- D. Mark vendor provided files as content and set the value for Copy to Output Directory to CopyAlways
Correct answer: B
Explanation
The correct answer is B because configuring StaticFiles in the startup Configure method allows the application to serve static files directly from the specified folder, thus enabling external websites to access them. Option A is incorrect as it requires additional overhead of creating a controller. Option C is also not suitable since DirectoryBrowser is not needed for serving static files. Option D does not address the issue of serving files over HTTP.