PrepAway - Latest Free Exam Questions & Answers

You are developing an ASP.NET MV…

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.

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 applications 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 the HandleErrorAttribute 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


Leave a Reply