exam questions

Exam 70-486 All Questions

View all questions & answers for the 70-486 exam

Exam 70-486 topic 1 question 107 discussion

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

You are developing an ASP.NET MVC application. The application includes the following HomeController class. Line numbers are included for reference only.

During testing, all errors display an ASP.NET error page instead of the expected error view.
You need to ensure that the error view displays when errors occur.
What should you do?

  • A. Replace line 01 with the following code segment: [HandleError(View="Error")]
  • B. In the web.config file, set the value of the customErrors property to On.
  • C. Replace line 01 with the following code segment: [HandleError(ExceptionType=typeof(SystemException))]
  • D. Create a custom error page named Error.aspx. Save the file in the Views\Shared folder for the project.
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
Enabling Custom Error Handling -
To enable custom error handling for use by a HandleErrorAttribute filter, add a customErrors element to the system.web section of the application's Web.config file, as shown in the following example:
<system.web>
<customErrors mode="On" defaultRedirect="Error" />
</system.web>
Note:
The HandleErrorAttribute attribute in ASP.NET MVC lets you specify how to handle an exception that is thrown by an action method. By default, when an action method with theHandleErrorAttribute attribute throws any exception, MVC displays the Error view that is located in the ~/Views/Shared folder.
Setting HandleErrorAttribute Properties
You can modify the default behavior of the HandleErrorAttribute filter by setting the following properties:
✑ ExceptionType. Specifies the exception type or types that the filter will handle. If this property is not specified, the filter handles all exceptions.
✑ View. Specifies the name of the view to display.
✑ Master. Specifies the name of the master view to use, if any.
✑ Order. Specifies the order in which the filters are applied, if more than one HandleErrorAttribute filter is possible for a method.
References:
https://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute(v=vs.118).aspx

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
Th4nat0r
Highly Voted 5 years, 1 month ago
Why not A? I think both A and B are correct in the same way.
upvoted 5 times
rosdra
4 years, 11 months ago
Also, it is not enough to set the value of the customErrors property to On but to set default value as well (view)
upvoted 1 times
...
...
slobex
Most Recent 4 years, 8 months ago
FINAL ANSWER: B https://stackify.com/aspnet-mvc-error-handling/
upvoted 3 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 ...