Which two actions should you perform?

You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5. The application has an ASPX page named ErrorPage.aspx.
You plan to manage the unhandled application exceptions.
You need to perform the following tasks:
Display the ErrorPage.aspx page Write the exceptioninformation in the Event log file.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)

You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5. The application has an ASPX page named ErrorPage.aspx.
You plan to manage the unhandled application exceptions.
You need to perform the following tasks:
Display the ErrorPage.aspx page Write the exceptioninformation in the Event log file.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)

A.
Add the following code fragment to the Web.config file.
<customErrors mode="On" defaultRedirect="ErrorPage.aspx" />

B.
Add the following code fragment to the Web.config file.
<customErrors mode="Off" defaultRedirect="ErrorPage.aspx" />

C.
Add the following code segment to the Global.asax file.
Private Sub Application_Error(sender As Object, e As EventArgs)
Dim exc As Exception = Server.GetLastError()
‘Write Exception details to event log
End Sub

D.
Add the following code segment to the ErrorPage.aspx file.
Private Sub Page_Error(sender As Object, e As EventArgs)
Dim exc As Exception = Server.GetLastError()
‘Write Exception details to event log
Server.ClearError()
End Sub

Explanation:
It is better to use Try/Catch blocks around any code that is subject to errors instead of relying on a global error handler.

An error handler that is defined in the Global.asax file will only catch errors that occur during processing of requests by the ASP.NET runtime. For example, it will catch the error if a user requests an .aspx file that does not occur in your application. However, it does not catch the error if a user requests a nonexistent .htm file. For non-ASP.NET errors, you can create a custom handler in Internet Information Services (IIS). The custom handler will also not be called for server-level errors.

You cannot directly output error information for requests from the Global.asax file; you must transfer control to another page, typically a Web Forms page. When transferring control to another page, use Transfer method. This preserves the current context so that you can get error information from the GetLastError method.
After handling an error, you must clear it by calling the ClearError method of the Server object (HttpServerUtility class).



Leave a Reply 0

Your email address will not be published. Required fields are marked *