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 thecustomErrorsproperty toOn.
C.
Replace line 01 with the following code segment:[HandleError(ExceptionType=typeof(SystemException))]
D.
Create a custom error page namedError.aspx. Save the file in the Views\\Shared folder for the project.
Explanation:
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.
https://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute(v=vs.118).aspx
B -https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/aspnet-error-handling
It’s B and D, isn’t it?
In order for D to work, you will need B first.
Why not A?
http://www.c-sharpcorner.com/article/handleerror-action-filter-in-asp-net-mvc/
Using View property of HandleError attribute, we can show the specified view on getting unhandled exceptions.